I understand that the background-size: cover property in CSS makes the background image as large as possible so that it covers the entire screen. However, because this can distort the image on larger screens, I want to be able to make the background image cover the width and height of the div container that it's in, rather than the width of the whole screen. I'm not sure how to do this. Even when placing my image inside a div in my HTML, the background-size: cover property still expands the image to the whole screen.
My CSS is:
.main {
height: 30vh;
text-align: center;
background: url("https://i.imgur.com/6FYizew.jpg");
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover
}
My HTML is:
<div class = "container" style = "padding-top: 5vh">
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class = "active hidden-xs"></li>
</ol>
<div class="carousel-inner">
<div class="item main active">
<div class = "hidden-xs" style = "width: 80%; max-width: 1200px; margin: auto; position: relative; top: 15%; padding-top: 30px; padding-bottom: 40px; background-color: rgba(255, 255, 255, 0.8);">
<h1 class = "hidden-xs" style = "font-size: 5em; font-weight: normal; color: #0b3c5d; font-weight: bold">TITLE</h1>
<hr class = "intro-divider hidden-xs" style = "width: 550px; background-color: #232f3f">
<h4 class = "hidden-xs" style = "margin-top: 15px; font-size: 1.5em; color: #232f3f"><em>SUBTITLE</em></h4>
</div>
</div>
Please let me know how I can set cover to cover just a container instead of the entire screen. Thanks!