html - 图像底部对齐

标签 html css

我有两个并排的 div,一个带有文本,另一个带有图像 CodePen Example :

<div class="wrapper">
  <div class="p1">    
    Lorem Ipsum is simply dummy text.        
  </div>
  <div class="p2">
    <img src="http://placehold.it/200x100">
 </div>    
</div>

还有 CSS:

div.wrapper {
  border: 1px solid red;
  width: 400px;
  .clear;
}

div.p1, div.p2 {
  float: left;
  width: 50%;
}

div.p1 {font-size: 36px;}

当文字高于图片时,图片底部有空格。

我希望图像始终与底部对齐。

更新

可以使用 inline-block 将两者都对齐到底部,但我无法将 50% 用于 div 宽度...为什么?如何解决?

我该怎么做?

谢谢你, 米格尔

最佳答案

试试这个: HTML:

<div class="wrapper clear">
  <div class="p1">
    Lorem Ipsum is simply dummy text.        
  </div>
  <div class="p2">
    <img src="http://placehold.it/200x100">
  </div>    
</div>

和 CSS:

.wrapper {
   border: 1px solid red;
   width: 400px;
   position:relative;
}

.p1{
   font-size: 36px;
   display: inline-block;
  margin:0;
  float:left;
  padding:0;
   width: 50%;
}

.p2{
  margin:0;
   display: inline-block;
   vertical-align: bottom;
  float:left;
  position:absolute;
  bottom:0;
   width: 50%;
   img{display: block;}
}


.clear {

  &:after {
    content: "";
    display: table;
    clear: both;
  } // :after

} // clear

http://codepen.io/anon/pen/byIda

编辑: 看到这个 http://codepen.io/anon/pen/klivC/

关于html - 图像底部对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23120842/

相关文章:

jquery - 滚动 spy : how do I get it to work?

javascript - 使用 HTML5 文件 API 在浏览器中创建音频列表

css - Xss 跨站脚本实践

html - 如何让div颜色出现在另一个前面?

javascript - 我想将一个字符串放入数组的每个值,如下面的代码所示。但我不想使用太多 if 运算符

html - 当容器滚动时,如何让子 div 使用所有可用空间?

Javascript 包含的函数在所有条件下都返回 false。只有其他部分被执行

html - CSS: anchor 和按钮的垂直对齐文本

html - html中的样式空白

HTML 选择不会使文本在 chrome 上居中