固定高度div底部显示问题
2013-07-08 21:46
369 查看
入行三年,觉得自己还是一个菜鸟。什么东西都懂一些,但是都不很深入 。决定以后要一个case,一个case的搞懂。j
今天开发一个项目,固定高度,文字需要在底部显示,这么简单的一个问题搞了很久,就别谈什么效率了。回家想了一下,总结出四个方法
1. 用margin-top
2. absolute 绝对定位
3. padding-top
4. table-cell
今天开发一个项目,固定高度,文字需要在底部显示,这么简单的一个问题搞了很久,就别谈什么效率了。回家想了一下,总结出四个方法
1. 用margin-top
fixHeight { height: 200px; border: 1px solid #F00; } .fixHeight .bottomShow{ margin-top: 160px; }
<div class="fixHeight"> <p class="bottomShow">margin-top</p> </div>这个方法不足时,如果修改了p的高度,需要改大量的css。
2. absolute 绝对定位
.fixHeight1 { border: 1px solid #F00; position: relative; height: 200px; text-align: center; overflow: hidden; } .fixHeight1 .bottomShow{ position: absolute; left: 0px; bottom: 10px; width: 100%; }
<div class="fixHeight1"> <p class="bottomShow">bottom</p> </div>这个方法不需要修改子元素的高度,不足之处在于改变元素的文档结构
3. padding-top
.fixHeight2 { height: 30px; padding-top:170px; border: 1px solid #F00; } .fixHeight2 .bottomShow{ height: 30px; line-height: 30px; }
<div class="fixHeight2"> <p class="bottomShow">padding-top</p> </div>这个方法需要修改东西比margin-top还要多
4. table-cell
.fixHeight3 { display: table-cell; margin-top: 5px; height: 200px; width: 100%; vertical-align: bottom; border: 1px solid #F00; }
<div class="fixHeight3"> <p class="bottomShow">底部显示</p> </div>这个方法的好处是不用再设置子元素,坏处是不兼容IE6、IE7。
相关文章推荐
- 不定高度的div背景或背景图片不显示问题
- div在IE6与IE7下显示高度不兼容的问题
- div显示在底部(一种固定不变,另一种随页面上下翻动而动)
- NO.24 关于左侧div固定宽度,右侧自适应时footer不能在最底部的问题
- IE6的png显示问题以及div无法实现1px高度问题的解决
- IE6 下div高度显示的问题
- Android RecycleView设置头部或者底部视图,给固定高度失效问题
- "把一个div标签,给它的属性设置position: fixed;bottom:0;固定在浏览器的最底部。 这个div标签在浏览器上下滚动的时候,会一直保持在屏幕最底部,这一点没有问题。但问题是当浏览
- 让文字在固定高度的div中垂直居中显示
- 在arcgis javascript 中map地图的div 总是显示高度400的问题
- div固定高度中图片垂直居中显示
- IE6下div边框显示有残缺 及 clear:both的纯间隔div高度问题
- 高度大于100%的fixed定位div显示不全问题(轻松解决)
- div文本溢出,隐藏显示,获取文本实际高度的问题
- 高度自适应100%显示,顶部和底部固定,中间自适应。左侧固定,右侧自适应的实例。
- 关于div的滚动条滚动到底部,内容显示不全的问题。(已解决)
- div显示在底部(一种固定不变,另一种随页面上下翻动而动)
- 解决IE6下div中文字显示竖排,IE7下div不能自适应高度问题
- 解决div的高度定义在IE6中不生效的问题
- 限制div高度当内容多了溢出时显示滚动条