Reputation: 1242
I've following code:
HTML
<div class="banner">
<img src="banner.png">
</div>
CSS
.banner > img {
margin: auto;
}
The Image have a width of 3000px and a height of 200px I want the image horizontal centered and no horizontal scroll bar. (Browser resizing should no problem then)
I've tried to give the .banner
div the banner image as background-image but then the div won't find it's size automatically ...
How is this possible?
Upvotes: 1
Views: 2471
Reputation: 71
Try this will work perfectly, add overflow-x
property to the class and set it to hidden
, That Will Disable The Horizontal Scroll Bar in CSS. See How to prevent horizontal scrolling? - Stack Overflow.
You can center the image by using these CSS properties:
display: flex;
.justify-content: center;
..banner {
overflow-x:hidden;
display: flex;
justify-content: center;
}
<div class="banner">
<img src="">
</div>
Upvotes: 3
Reputation: 7720
Your best option is using the images as background, but if you want/need to use the image, do it like this
.banner{overflow:hidden; height:200px; width:100%; text-align:center;}
.banner img{width:100%; height:100%; margin:0 auto;}
Upvotes: 3