Reputation: 63
I am trying to resolve an issue where I have followed multiple tutorials on how to make an image within a container responsive. I have done everything I feel I can but for some reason the image still doesnt fill the box.
I have also tried importing the image with CSS and using the background: cover; property.
How can I make this image FILL the left column, and for the text to remain on the right hand side?
#about .container {
background-color: #fff;
padding: 0;
height: 300px;
margin: 20px auto;
text-align: center;
box-shadow: 0px 0px 40px -10px rgba(59, 66, 71, 1);
border: 0.5px solid #72A7A3;
}
.about-photo img {
width: 100%;
height: auto;
}
<section id="about">
<div class="container-fluid">
<div class="container col-6">
<div class="row">
<div class="col-5 about-photo">
<img src="img/avatar.jpg" class="img-fluid">
</div>
<div class="col-7 about-text">
<h1>Hi, I'm <span class="text-primary">Oliver Stott</span></h1>
<p>thisi s a test </p>
</div>
</div>
</div>
</div>
</section>
Upvotes: 0
Views: 790
Reputation: 1335
Sice you already know the height of container,
try this
1) if you dont want to stretching the image while resizing,
#about .container {
background-color: #fff;
padding: 0;
height: 300px;
margin: 20px auto;
text-align: center;
box-shadow: 0px 0px 40px -10px rgba(59, 66, 71, 1);
border: 0.5px solid #72A7A3;
}
.about-photo .img {
width: 100%;
height: 300px;
background: #eee url('https://images.pexels.com/photos/66997/pexels-photo-66997.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940');
-webkit-background-size: cover;
background-size: cover;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<section id="about">
<div class="container-fluid">
<div class="container col-6">
<div class="row">
<div class="col-5 about-photo">
<!-- <img src="https://images.pexels.com/photos/66997/pexels-photo-66997.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" class="img-fluid"> -->
<div class="img"></div>
</div>
<div class="col-7 about-text">
<h1>Hi, I'm <span class="text-primary">Oliver Stott</span></h1>
<p>thisi s a test </p>
</div>
</div>
</div>
</div>
</section>
2) if stretching is fine, do this : change
.about-photo img {
height: 100%; // from auto to 100%
}
and add
#about .container .row{
height: 100%
}
#about .container {
background-color: #fff;
padding: 0;
height: 300px;
margin: 20px auto;
text-align: center;
box-shadow: 0px 0px 40px -10px rgba(59, 66, 71, 1);
border: 0.5px solid #72A7A3;
}
.about-photo img {
width: 100%;
height: 100%;
}
#about .container .row{
height: 100%
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<section id="about">
<div class="container-fluid">
<div class="container col-6">
<div class="row">
<div class="col-5 about-photo">
<img src="https://images.pexels.com/photos/66997/pexels-photo-66997.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940" class="img-fluid">
</div>
<div class="col-7 about-text">
<h1>Hi, I'm <span class="text-primary">Oliver Stott</span></h1>
<p>thisi s a test </p>
</div>
</div>
</div>
</div>
</section>
Upvotes: 0
Reputation: 7991
Just add w-100
class to img
if you want image fit into parent element.
<section id="about">
<div class="container-fluid">
<div class="container col-6">
<div class="row">
<div class="col-5 about-photo"> <img src="img/avatar.jpg" class="img-fluid w-100">
</div>
<div class="col-7 about-text">
<h1>Hi, I'm
<span class="text-primary">Oliver Stott</span>
</h1>
<p>this is a test </p>
</div>
</div>
</div>
</div>
</section>
Upvotes: 2
Reputation: 725
This should work:
.about-photo
{ background-image : url(img/avatar.jpg);
background-size: cover;
}
Upvotes: -1