700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 三种绝对定位元素的水平垂直居中的办法

三种绝对定位元素的水平垂直居中的办法

时间:2018-06-18 00:47:47

相关推荐

三种绝对定位元素的水平垂直居中的办法

web前端|css教程

水平,元素,定位

web前端-css教程1.css实现居中

办公用品网上采购系统源码,ubuntu离线安装驱动,爬虫技术有scrapy,php代码生成器使用教程学习,长春seo教程lzw

缺点:需要提前知道元素的宽度和高度。

品牌微推 源码,ubuntu命令界面保存,爬虫打印response值,php 小偷,京东seo技巧lzw

Document.box{ width: 600px; height: 400px; position: absolute; left: 50%; top: 50%; border:1px solid #000; background:red; margin-top: -200px; /* 高度的一半 */ margin-left: -300px; /* 宽度的一半 */ }

发卡源码授权,vscode打开bin文件,ubuntu卡桌面,tomcat自动解压,sqlite3 主键 类型,爬虫击杀秀完整版视频,微盾加密php,唐山seo数据监控,网站首页源代码,流程图 网页版,织梦响应式企业模板lzw

2、css3实现水平垂直居中

注意:无论元素的尺寸是多少,都可以居中。不过IE8以上才兼容这种写法,移动端可忽略。

Document.box{ width: 600px; height: 400px; position: absolute; left: 50%; top: 50%; border:1px solid #000; background:red; transform: translate(-50%, -50%); /* 50%为自身尺寸的一半 */ }

3、margin:auto实现居中

Document.box{ width: 600px; height: 400px; position: absolute; left: 0; top: 0; right: 0; bottom: 0; border:1px solid #000; background:red; margin: auto; /* 有了这个就自动居中了 */ }

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