[英]Image inside div container has a 5px gap at the bottom
If you go to my Website that i am working on: 如果您访问我正在从事的我的网站:
http://lastdeath.de/kaufmannmike/wallpaper.html http://lastdeath.de/kaufmannmike/wallpaper.html
You can see 2 images ( img
) both inside 2 different div
elements. 您可以在2个不同的
div
元素中看到2张图像( img
)。 Something is weird there. 那里有些奇怪。 The images have 5 bottom pixels, even if I don't set it anyways.
图像有5个底部像素,即使我没有设置也是如此。 I've just put an
img
element in a class="content"
and then in div id="breaker/boxer"
, nothing really complicated. 我只是将
img
元素放在class="content"
,然后放在div id="breaker/boxer"
,没有什么真正复杂的。
But the code just don't want to work. 但是代码只是不想工作。
i can make a line code of an img
, then there are no problems with these 5 pixels on the bottom. 我可以制作一个
img
的线路代码,那么底部的这5个像素没有问题。 But i need to put the img
in a div
container. 但是我需要将
img
放在div
容器中。
Code: 码:
body { background-color: #fafafa; margin: 0; padding: 0; } .content { overflow: hidden; padding-top: 80px; } img { height: 100%; width: 100%; }
<div class="content"> <div max-height="480px" id="breaker"> <img src="http://lastdeath.de/kaufmannmike/img/2_work/wallpaper/breaker-wallpaper_long.jpg"> </div> <div id="boxer"> <img src="http://lastdeath.de/kaufmannmike/img/2_work/wallpaper/boxer-wallpaper_long.jpg"> </div> </div>
How to fix this? 如何解决这个问题?
just set your img
to display:block
只需将您的
img
设置为display:block
why? 为什么? because default value of
img
is display:inline
因为
img
默认值为display:inline
so instead of this: 所以代替这个:
img {
height: 100%;
width: 100%;
}
you should have this: 你应该有这个:
img {
display:block;
height: 100%;
width: 100%;
}
Here is a working snippet based on your code taken from your site: 以下是根据您从网站获取的代码得出的有效代码段:
body { background-color: #fafafa; margin: 0; padding: 0; } .content { overflow: hidden; padding-top: 80px; } img { display:block; height: 100%; width: 100%; }
<div class="content"> <div max-height="480px" id="breaker"> <img src="http://lastdeath.de/kaufmannmike/img/2_work/wallpaper/breaker-wallpaper_long.jpg"> </div> <div id="boxer"> <img src="http://lastdeath.de/kaufmannmike/img/2_work/wallpaper/boxer-wallpaper_long.jpg"> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.