There is h1,p,a in a div, I want h1 in the top of the div, and a in the bottom of the div, and p in the middle no matter the height of p.

在div中有h1,p,a,我想在div的顶部使用h1,在div的底部使用a,在p的中间使用p而不管p的高度。

jsfiddle

Here is source:

这是来源:

html

<div class="box">    
  <div>
    <h1>Header</h1>
    <p>text <br>line2<br>line3</p>
    <a href="#">bottom</a>
  </div>
  <div>
    <h1>Header</h1>
    <p>text <br>line2</p>
    <a href="#">bottom</a>
  </div>
</div>

css

.box {
  box-sizing: border-box;
  padding: 0 1px;
  margin: 0;
  overflow: hidden;
  clear: both;
  border: 1px solid blue;
}
.box div {
  float: left;
  width: 50%;
  box-sizing: border-box;
  padding: 10px;
}
.box h1 {
  padding: 0;
  margin: 0 0 10px;
}
.box p {
  padding: 0;
  margin-right:5px;
  text-wrap:normal;
}
.box a {
}

2 个解决方案

#1


Check following solution works for you:

检查以下解决方案是否适合您:

html, body{
    height:100%;
}
.box {
    border: 1px solid blue;
    box-sizing: border-box;
    clear: both;
    height: 100%;
    margin: 0;
    overflow: hidden;
    padding: 0 1px;
    position: relative;
}
.box div {
    bottom: 0;
    box-sizing: border-box;
    display: inline-block;
    height: 100%;
    position: relative;
    top: 0;
    vertical-align: top;
    width: 50%;
}
.box h1 {
    margin: 0 0 10px;
    padding: 0;
}
.box p {
    margin-right: 5px;
    padding: 0;
}
.box a {
    bottom: 0;
    position: absolute;
}
<div class="box">    
    <div>
      <h1>Header</h1>
      <p>text <br>line2<br>line3</p>
      <a href="#">bottom</a>
    </div><div>
      <h1>Header</h1>
      <p>text <br>line2</p>
      <a href="#">bottom</a>
    </div>
</div>

更多相关文章

  1. 让列在3列CSS布局中扩展到相同的高度?
  2. 纯CSS最小化高度标题,绝对定位DIV内最大化身高
  3. CSS Transition div容器高度从100%到200%
  4. 保持子div的宽高比与父级的高度和宽度变化
  5. 自动设置绝对子级的父div的高度
  6. 浮动到页面底部的可变高度页脚的CSS(不是视口)
  7. 100%高度分区内显示:表格单元分区
  8. html2canvas 识别 svg 解决方案
  9. JQuery基于元素的高度添加类

随机推荐

  1. android上传文件至服务器(android端+服务
  2. 创建 Cordova/Phonegap for Android 项目
  3. 总结EditText,TextView使用的点点滴滴
  4. android 如何绕过签名校验
  5. Android 字体和颜色
  6. html5 video自动播放-Android、IOS video
  7. Qt for Android获取手机热点开关状态
  8. Android 中使用自定义字体的方法
  9. Android基础————UI布局之高级控件详
  10. 在LinearLayout中嵌套RelativeLayout来设