I have a question about image positioning and sizing in DIV. I have an image that I use in a specific DIV and I need it to cover the whole topside of the DIV. When I zoom-in the scale of the browser, instead of shrinking in the DIV, the image disappears and overflows from the right side of the DIV. Also when I zoom-out the scale, the image is being cut-off from the bottom. I know the problem is with the Height, but I do not know how to fix it.
.main_body {
background-color: white;
margin: auto;
margin-top: 150px;
max-width: 78.3%;
height: 500px;
-webkit-box-shadow: 0px 0px 15px 0px rgba(50, 50, 50, 0.87);
-moz-box-shadow: 0px 0px 15px 0px rgba(50, 50, 50, 0.87);
box-shadow: 0px 0px 15px 0px rgba(50, 50, 50, 0.87);
}
.upper_main {
background-image: url("upper_title.png");
background-repeat: no-repeat;
background-size: cover;
height: 8%;
}
<div class="main_body">
<div class="upper_main">
</div>
</div>
Why not simply use an image that take the full width of the top bar :
.main_body {
background-color: white;
margin: auto;
margin-top: 150px;
max-width: 78.3%;
height: 500px;
-webkit-box-shadow: 0px 0px 15px 0px rgba(50, 50, 50, 0.87);
-moz-box-shadow: 0px 0px 15px 0px rgba(50, 50, 50, 0.87);
box-shadow: 0px 0px 15px 0px rgba(50, 50, 50, 0.87);
}
.upper_main img {
width:100%;
}
<div class="main_body">
<div class="upper_main">
<img src="https://lorempixel.com/300/50/" >
</div>
</div>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments