简体   繁体   English

对齐div的图像底部

[英]Aligning image bottom of div

I'm trying to format an image so it aligns to the bottom of a div. 我正在尝试格式化图像,使其与div的底部对齐。 I put what I think is the relevant code in a fiddle: http://jsfiddle.net/5KEyD/ 我把我认为是相关代码的东西放在小提琴中: http : //jsfiddle.net/5KEyD/

<div id="main">
<div style="display: inline-block; margin-left: 15px">
<div id="imageWrapper">
<img id="bottomImage" class="aligncenter" src="Bottom-Text.png" alt="Some Image" width="800" height="152" /></div>    </div></div> 

#main{width:800px; height: 200px; padding-right:40px; overflow:hidden; background-    color: #c0c0c0;}
#imageWrapper { position: relative; height: 152px; } /* height is for display purposes only */
#bottomImage { position: absolute; bottom: 0px; }  

What I need is for the image to align (centered) all the way at the bottom, with no extra grey space under it. 我需要的是图像始终在底部对齐(居中),其下方没有多余的灰色空间。

Thanks for any help! 谢谢你的帮助!

修改后的网页

<div style="width: 800px; margin: 0 auto;">
    <div id="imageWrapper">
        <img id="bottomImage" class="aligncenter" src="/wp-content/uploads/2014/05/Bottom-Text.png" alt="Some Image" width="800" height="152">
    </div>
</div>

I think that happens because of using display: inline-block for div element. 我认为这是因为对div元素使用display:inline-block。 Inline-block rule always adds 5px margins to element. 内联阻止规则始终向元素添加5px的边距。 So if you remove it the issue will be fixed . 因此,如果将其删除, 该问题将得到解决 If you need that rule you can add -5px bottom margin . 如果您需要该规则,则可以添加-5px底边距

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM