如何将图片与另一张图片的底部对齐?

时间:2015-09-15 19:13:32

标签: html css

如何对齐浣熊图片,使其出现在大圆形图片的右下角?就像它在图像上一样。

我尝试了背景位置:右下角;以及位置:绝对;但它没有用。

请参阅下面的代码。

谢谢。

enter image description here



.p-i--1 {
  background-image: url(http://www.zerohedge.com/sites/default/files/pictures/picture-3930.jpg);
}
.p-i {
  border-radius: 50%;
  background-position: bottom right;
  width: 40px;
  height: 40px;
  position: absolute;
}
.p-1 {
  float: left;
  width: 220px;
  height: 100%;
  position: relative;
}
.p-wrap {
  bottom: 0;
  width: 100%;
  text-align: center;
}
.pic-wrap {
  width: 122px;
  height: 122px;
  margin: 0 auto;
}
.p_pic-1 {
  background-image: url(http://www.fernomortuary.com/~/media/products-mortuary/swatches/Swatch_Burgundy.ashx?w=122);
  background-position: center;
  float: left;
  width: 122px;
  height: 122px;
  -webkit-border-radius: 50%;
  -moz-border-radius: 50%;
  border-radius: 50%;
}
.p-description {
  font-family: Roboto;
  font-weight: 300;
  color: #666;
  font-size: 14px;
  text-align: center;
  float: left;
  margin-top: 0;
}
.p-name {
  text-align: center;
}

<div class="p-1">
  <div class="p-i--1 p-i"></div>
  <div class="pic-wrap">
    <a class="p_pic-1" href="index.html"></a>
  </div>
  <div class="p_wrap">
    <h4 class="p-name">Some text</h4>
    <p class="p-description">Some very very very very long description</p>
  </div>
</div>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:3)

将较小的图片放在.pic-wrap内。给它一个absolute位置,并使用bottomright属性对齐:

JS Fiddle

进行了CSS更改:

.pic-wrap {
  position: relative;
}
.p-i { 
    position: absolute;
    bottom: 0;
    right: 0;
}

如果你想要小图像周围的白色边框:

.p-i { 
   border: 3px solid white;
}

JS Fiddle

答案 1 :(得分:0)

只需将bottomright属性添加到您的绝对元素中,如下所示:

.p-i {
  border-radius: 50%;
  background-position: bottom right;
  width: 40px;
  height: 40px;
  position: absolute;
  bottom: 100px;
  right: 50px;
}

以下是上述代码的代码段:

.p-i--1 {
  background-image: url(http://www.zerohedge.com/sites/default/files/pictures/picture-3930.jpg);
}
.p-i {
  border-radius: 50%;
  background-position: bottom right;
  width: 40px;
  height: 40px;
  position: absolute;
  bottom: 100px;
  right: 50px;
}
.p-1 {
  float: left;
  width: 220px;
  height: 100%;
  position: relative;
}
.p-wrap {
  bottom: 0;
  width: 100%;
  text-align: center;
}
.pic-wrap {
  width: 122px;
  height: 122px;
  margin: 0 auto;
}
.p_pic-1 {
  background-image: url(http://www.fernomortuary.com/~/media/products-mortuary/swatches/Swatch_Burgundy.ashx?w=122);
  background-position: center;
  float: left;
  width: 122px;
  height: 122px;
  -webkit-border-radius: 50%;
  -moz-border-radius: 50%;
  border-radius: 50%;
}
.p-description {
  font-family: Roboto;
  font-weight: 300;
  color: #666;
  font-size: 14px;
  text-align: center;
  float: left;
  margin-top: 0;
}
.p-name {
  text-align: center;
}
<div class="p-1">
  <div class="p-i--1 p-i"></div>
  <div class="pic-wrap">
    <a class="p_pic-1" href="index.html"></a>
  </div>
  <div class="p_wrap">
    <h4 class="p-name">Some text</h4>
    <p class="p-description">Some very very very very long description</p>
  </div>
</div>

答案 2 :(得分:0)

这是一个小提琴:https://jsfiddle.net/6sxLj3hL/ 您在容器上的硬编码高度是不必要的,所以我将其删除了。

.p-i--1 {
    background-image: url(http://www.zerohedge.com/sites/default/files/pictures/picture-3930.jpg);
}
.p-i {
    border-radius: 50%;
    background-position: bottom right;
    width: 40px;
    height: 40px;
    float:right

}
.p-1 {
    float: left;
    width: 220px;
    height: 100%;
    position: relative;
}
.p-wrap {
    bottom: 0;
    width: 100%;
    text-align: center;
}
.pic-wrap {
    width: 122px;
    margin: 0 auto;
    overflow: auto;
}
.p_pic-1 {
    background-image: url(http://www.fernomortuary.com/~/media/products-mortuary/swatches/Swatch_Burgundy.ashx?w=122);
    background-position: center;
    width: 122px;
    height: 122px;
    -webkit-border-radius: 50%;
    -moz-border-radius: 50%;
    border-radius: 50%;
    display: block;
    overflow: auto;
}
.p-description {
    font-family: Roboto;
    font-weight: 300;
    color: #666;
    font-size: 14px;
    text-align: center;
    float: left;
    margin-top: 0;
}
.p-name {
    text-align: center;
}

我重新安排了你的HTML

<div class="p-1">
    <div class="pic-wrap"> 
        <a class="p_pic-1" href="index.html"></a>
        <div class="p-i--1 p-i"></div>
    </div>
    <div class="p_wrap">
         <h4 class="p-name">Some text</h4>
        <p class="p-description">
            Some very very very very long description
        </p>
    </div>
</div>