如何将图片放置在div的右下角

19

你也可以尝试使用background-image - Gumbo
5个回答

31

有几种方法可以做到这一点。最简单的方法:

<div class="outer">
<img src="....">
</div>

使用

div.outer { position: relative; height: 24px; }
div.outer img { position: absolute; right: 0; bottom: 0; }

现在这将使它脱离正常流程,如果你希望其他内容环绕/浮动在它周围,那就是一个问题。在这种情况下,您确实需要知道图像的高度,然后根据您拥有的内容应用适当的技巧。

Making the absolute, relative开始。

例如,如果图像高度为10像素,您可以尝试以下操作:

div.outer { height: 24px; }
div.outer { float: right; margin-top: 14px; }
当然,14像素来自于24像素减去10像素。不过我不知道这是否能满足您的需求。

关于第一个代码,只需将bottom:0与右侧定位一起使用即可。肯定感谢您的支持。 - bresleveloper
我不能评论Cletus的答案,但是我不得不在“right: 0; bottom: 0;”中添加“px”,因此它变成了:right: 0px; bottom: 0px; 在我的情况下,如果我没有使用“px”后缀,就算我输入其他值也无法正常工作。 - Jxadro

0

背景图片是你的解决方案。

<div class="blarg" style="background:url(image.gif) bottom right no-repeat">Content</div>

如果需要的话,您可能需要调整div的填充,以便div的内容不会重叠在您的图片上。


0
如果你想让文字环绕在图片周围,那么这两个答案都是错误的。两者都会使文字直接覆盖在图片上。我已经寻找了几个小时,似乎没有真正的答案存在。这篇文章更清楚地解释了为什么这两个答案在尝试环绕文本时不起作用。

0
<div class='main'>
    <div>...</div>
    <div>...</div>
    <div class="img-div">
      <img src="....">
    </div>
</div>


div.main { 
   height: 1164px;
   width: 900px; 
}
div.img-div {
   position: absolute;
   top: 1084px;
   left: 817px;
   margin: .75rem;
}

假设图像的尺寸为57*55。

enter image description here


-1

仅用于将图像定位在右下角: 我有一个"Div"和图像在div中,小图像位于div的右下角。

enter image description here Detailed: https://jsfiddle.net/ez08vL7w/

       <html>
        <head> 
        </head>
        <body> 
<div style=" position:relative; display: inline-block">
  <img style="width: 100px; height: 100px; position: absolute; z-index: 4; bottom: 50px; right: 30px; " 
    src="http://images.unsplash.com/photo-1529736576495-1ed4a29ca7e1?ixlib=rb-1.2.1&q=80&fm=jpg&crop=entropy&cs=tinysrgb&w=1080&fit=max"/>
            
   <a href ="" target="_blank"> 
    <img src="https://media.gettyimages.com/photos/tiger-portrait-picture-id949472768?s=612x612"/> </a>
            
            </div> 
            </body> 
        </html>

简体中文:

<div style=" position:relative; display: inline-block">
      <img style="width: 100px; height: 100px; position: absolute; z-index: 4; bottom: 50px; right: 30px; " 
        src=""/> 

        <img src=""/>  
          </div> 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接