最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
CSS实现垂直居中方法
时间:2022-07-02 12:39:59 编辑:袖梨 来源:一聚教程网
这种方法,在 content 元素外插入一个 div。设置此 div height:50%; margin-bottom:-contentheight;。
content 清除浮动,并显示在中间。
Content here
#floater {float:left; height:50%; margin-bottom:-120px;}
#content {clear:both; position:relative;}
优点:
适用于所有浏览器
没有足够空间时(例如:窗口缩小) content 不会被截断,滚动条出现
缺点:
唯一我能想到的就是需要额外的空元素了(也没那么糟,又是另外一个话题)
方法四
这个方法使用了一个 position:absolute,有固定宽度和高度的 div。这个 div 被设置为 top:0; bottom:0;。但是因为它有固定高度,其实并不能和上下都间距为 0,因此 margin:auto; 会使它居中。使用 margin:auto;使块级元素垂直居中是很简单的。
Content here
#content {
position:absolute;
top:0;
bottom:0;
left:0;
right:0;
margin:auto;
width:70%;
}
优点:简单
缺点:
IE(IE8 beta)中无效
无足够空间时,content 被截断,但是不会有滚动条出现
相关文章
- 蓝色星原旅谣碧空之下如何 蓝色星原旅谣碧空之下分享 09-09
- c语言栈解决背包问题求解|递归回溯思路与代码示例 09-09
- 【c语言编程软件电脑版下载】官方渠道与安装步骤 09-09
- 小熊猫c语言编程软件怎么安装和使用 09-09
- C语言编辑器IDE怎么选 09-09
- c语言编写程序软件怎么入手 09-09