1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 浅谈使用CSS实现元素垂直居中的几种方法

浅谈使用CSS实现元素垂直居中的几种方法

时间:2022-12-09 17:52:51

相关推荐

浅谈使用CSS实现元素垂直居中的几种方法

web前端|css教程

CSS,元素垂直居中

web前端-css教程

偷网站源码的软件,ubuntu手机上网,tomcat9设置启动参数,爬虫沙消毒,php面试逻辑技术题学习,seo顾问合同lzw

利用CSS进行元素的水平居中,行级元素设置其父元素的text-align center,块级元素设置其本身的left 和 right margins为auto即可。本文收集了六种利用css进行元素的垂直居中的方法,一起看看吧!

手机薄荷锁机源码,安装ubuntu 安全启动,tomcat8性能测试,pytho爬虫基础,php如何写日志,舞钢SEOlzw

Line-Height Method

易语言网站攻击源码,vscode浏览器使用教程,ubuntu升級,tomcat怎样卸安装,反人类爬虫,php操作手册,杭州提升关键词排名seo,表情网站源码lzw

试用:单行文本垂直居中,demo

代码:

html

Text here

css

#child { line-height: 200px;}

垂直居中一张图片,代码如下

html

css

#parent { line-height: 200px;}#parent img { vertical-align: middle;}

CSS Table Method

适用:通用,demo

代码:

html

Content here

css

#parent {display: table;}#child { display: table-cell; vertical-align: middle;}

低版本 IE fix bug:

#child { display: inline-block;}

Absolute Positioning and Negative Margin

适用:块级元素,demo

代码:

html

Content here

css

#parent {position: relative;}#child { position: absolute; top: 50%; left: 50%; height: 30%; width: 50%; margin: -15% 0 0 -25%;}

Absolute Positioning and Stretching

适用:通用,但在IE版本低于7时不能正常工作,demo

代码:

html

Content here

css

#parent {position: relative;}#child { position: absolute; top: 0; bottom: 0; left: 0; right: 0; width: 50%; height: 30%; margin: auto;}

Equal Top and Bottom Padding

适用:通用,demo

代码:

html

Content here

css

#parent { padding: 5% 0;}#child { padding: 10% 0;}

Floater p

适用:通用,demo

代码:

html

Content here

css

#parent {height: 250px;}#floater { float: left; height: 50%; width: 100%; margin-bottom: -50px;}#child { clear: both; height: 100px;}

以上就是六种方法,可以在实际的使用过程中合理选择.

编程入门!!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。