如下图所示效果,可以使用表格实现,本文采用在CSS中实现。

标记如下:

<div class="wrapper">
<div class="box">
<h1>Andy Budd</h1>
<p> ... </p>
<div class="bottom"></div>
</div>
<div class="box">
<h1>Richard Rutter</h1>
<p> ... </p>
<div class="bottom"></div>
</div>
<div class="box">
<h1>Jeremy Keith</h1>
<p> ... </p>
<div class="bottom"></div>
</div>
</div>

在实例中,有3个div,每列一个div,每个div中包括标题、内容、空的div,这个空的div作为底角的钩子,将这3个div放入容器div中,使用容器div限制高度,下述代码给框设置样式:

.wrapper {
width: 100%;
}
.box {
width: 250px;
margin-left: 20px;
float: left;
display: inline;
padding: 20px;
background: #89ac10 url(chapter08/img/top.gif) no-repeat left top; /*图片使得上面两个角成为圆角*/
}

运行结果如下:产生3个高度不一致的列

产生高度相等的三列的关键技术在于:给每个框设置大的底内边距(220px),然后用数值相似的负外边距(-200px)来消除这个高度。

.wrapper {
float: left;
border: solid 1px black;
width: 100%;
}
.box {
width: 250px;
padding-left: 20px;
padding-right: 20px;
padding-top: 20px;
padding-bottom: 220px;
margin-bottom: -200px;
margin-left: 20px;
float: left;
display: inline;
background: #89ac10 url(chapter08/img/top.gif) no-repeat left top;
}

通过给容器浮动、添加边框,可以看到这样导致每个列溢出容器元素。

.wrapper {
border: solid 1px black;
width: 100%;
overflow:hiddden;
}
.box {
width: 250px;
padding-left: 20px;
padding-right: 20px;
padding-top: 20px;
padding-bottom: 220px;
margin-bottom: -200px;
margin-left: 20px;
float: left;
display: inline;
background: #89ac10 url(chapter08/img/top.gif) no-repeat left top;
}

如果把容器的overflow设置为hidden,列在最高点被剪裁,220px和-200px形成的20px的差值在每个框的底部形成可见的内边距。

下面把列的底边定位在正确的位置,需要它们与容器的底部对齐:为此,把容器的position设置为relative,然后将空div的position设置为absolute,再将它们的bottom设置为0,只要给它们设置正确的宽高,就能应用底部背景图像。

.wrapper {
border: solid 1px black;
width: 100%;
overflow:hiddden;
position: relative;
}
.box {
width: 250px;
padding-left: 20px;
padding-right: 20px;
padding-top: 20px;
padding-bottom: 220px;
margin-bottom: -200px;
margin-left: 20px;
float: left;
display: inline;
background: #89ac10 url(chapter08/img/top.gif) no-repeat left top;
}
.bottom {
position: absolute;
bottom:;
height: 20px;
width: 290px;
background: #89ac10 url(chapter08/img/bottom.gif) no-repeat left bottom;
margin-left: -20px;/*因为在.box中设置了margin-left为20px,则.bottom向右移动了20px(如最后一图),所以设置-20px让它左移*/
}

最新文章

  1. flex总结
  2. Topcoder SRM558 1000 SurroundingGame
  3. 布局容器layout Container
  4. 改变TableView中的分割线位置
  5. 使用 Socket 通信实现 FTP 客户端程序(来自IBM)
  6. Plextor 浦科特M7VC性能
  7. 转换framebuffer实现安卓截图
  8. 在O(1)时间删除链表结点
  9. PL/SQL设置关键字大写
  10. hadoop-1.1.2 在Windows环境下的部署
  11. MFC基础程序设计VS2015 最新03
  12. UNIX网络编程——客户/服务器程序设计示范(三)
  13. Extjs 在Grid单元中格添加Tooltip提示
  14. 四则运算生成器功能完善&amp;&amp;界面设计——结对项目
  15. Linux查看GPU使用情况
  16. Ubuntu:搜狗输入法不能输入中文
  17. C高级第三次作业(1)
  18. ZK分布式锁(未完 待续)
  19. C++雾中风景5:Explicit&#39;s better than implicit.聊聊Explicit.
  20. write()和prinln()的区别?

热门文章

  1. 战争游戏OverTheWire:Bandit(一)
  2. svn检出两种方式的区别
  3. 关于找不到指定的模块,异常来自HRESULT:0x8007007E的解决方法
  4. 指令——mdadm
  5. Android Studio中 安卓模拟器 联网
  6. 简单bat脚本
  7. 3、gitlab备份与恢复
  8. Cake ZOJ - 3537
  9. maven热部署
  10. Python 基础之正则之一 单字符,多字符匹配及开头结尾匹配