div居中问题
来源:互联网 发布:suse12网络配置端口 编辑:程序博客网 时间:2024/06/04 18:31
水平居中:给div设置一个宽度,然后添加margin:0 auto属性
div{ width:200px; margin:0 auto; }
让绝对定位的div居中
div { position: absolute; width: 300px; height: 300px; margin: auto; top: 0; left: 0; bottom: 0; right: 0; background-color: pink; /* 方便看效果 */}
水平垂直居中一
确定容器的宽高 宽500 高 300 的层设置层的外边距div { position: relative; /* 相对定位或绝对定位均可 */ width:500px; height:300px; top: 50%; left: 50%; margin: -150px 0 0 -250px; /* 外边距为自身宽高的一半 */ background-color: pink; /* 方便看效果 */ }
水平垂直居中二
未知容器的宽高,利用 `transform` 属性div { position: absolute; /* 相对定位或绝对定位均可 */ width:500px; height:300px; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: pink; /* 方便看效果 */}
水平垂直居中三
利用 flex 布局实际使用时应考虑兼容性.container { display: flex; align-items: center; /* 垂直居中 */ justify-content: center; /* 水平居中 */}.container div { width: 100px; height: 100px; background-color: pink; /* 方便看效果 */}
0 0
- div居中问题
- 解决DIV居中问题
- DIV居中问题
- div居中的问题
- div居中问题
- SPAN DIv居中问题
- div垂直居中问题
- div居中问题
- div居中问题
- DIV盒子居中问题
- div 居中问题
- IE 的 DIV居中问题
- css+div 文字居中问题
- 关于DIV高度居中问题
- IE css DIV 居中问题
- div中的table居中问题
- div的上下左右居中问题
- canvas a div居中问题
- QT数据库--添加MySQL驱动插件(ARM篇)
- andriodStudio真机运行 installation failes with message INSTALL_CANCELED_BY_USER 错误
- 算法工具包
- 388.Permutation Sequence-第k个排列(中等题)
- 学习笔记之——自定义带滑动距离监控和仿iOS回弹效果的ScrollView
- div居中问题
- QT数据库--添加MySQL驱动插件(Linux篇)
- linux环境下安装curses库(包含库文档安装)
- qt配置 QSetting使用方法
- 【C语言】判断一个字符串是否为另一个字符串的回旋字符串
- QT数据库--添加MySQL驱动插件(mingwin32)
- codeforce 724D Dense Subsequence (字符串||贪心好题)
- ASUS EZ Installer v1.02.11
- iOS开发-模仿网易新闻首页联合滚动动画