3个不同div中的3个段落的水平对齐

时间:2015-11-09 22:28:45

标签: html css alignment

我不能使用float因为它们没有被包裹在一起。这就是它的样子: Click Here to see the mockup . A verbal explanation would be too clumsy

2 个答案:

答案 0 :(得分:1)

如果底部p的高度固定,可以使用一种可能的选项



.wrapper {
  display: -webkit-flex;
}

.item {
  position: relative;
  border: 1px solid black;
  padding: 20px 20px 100px 20px;
  margin: 10px;
}

.bottom {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 100px;
  padding: 0;
  margin: 0;
  border: 1px solid red;
}

<div class="wrapper">
  <div class="item">
      <p>Other Stuff</p>
      <p class="bottom">Bootom</p>
  </div>
  <div class="item">
      <p>Other Stuff</p>
      <p>Other Stuff</p>
      <p>Other Stuff</p>
      <p>Other Stuff</p>
      <p class="bottom">Bootom</p>
  </div>
  <div class="item">
      <p>Other Stuff</p>
      <p>Other Stuff</p>
      <p class="bottom">Bootom</p>
  </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您可以将div设置为images,然后将position: relative代码设置为<p>,然后从底部给出一个百分比以满足您的需求。

代码和演示:

position:absolute

CSS:

<div class="div1">
   <p>I'm some random text</p>
</div>
<div class="div2">
   <p>I'm some random text</p>
</div>
<div class="div3">
   <p>I'm some random text</p>
</div>

CODEPEN DEMO