div在另一个div里垂直居中的示例介绍
基础知识:div在另一个div里 垂直居中
方法一:
<span style="text-decoration: none;">.parent {<br> width:800px;<br> height:500px;<br> border:2px solid #000;<br> position:relative;<br> }<br> .child {<br> width:200px;<br> height:200px;<br> margin: auto; <br> position: absolute; <br> top: 0; left: 0; bottom: 0; right: 0; <br> background-color: red;<br>}<br></span>
登录后复制
方法二:
<span style="text-decoration: none;">.parent {<br> width:800px;<br> height:500px;<br> border:2px solid #000;<br> display:table-cell;<br> vertical-align:middle;<br> text-align: center;<br> }<br> .child {<br> width:200px;<br> height:200px;<br> display:inline-block;<br> background-color: red;<br> }<br></span>
登录后复制
方法三:
<span style="text-decoration: none;">.parent {<br> width:800px;<br> height:500px;<br> border:2px solid #000;<br> display:flex;<br> justify-content:center;<br> align-items:center;<br> }<br> .child {<br> width:200px;<br> height:200px;<br> background-color: red;<br> }<br></span>
登录后复制
方法四:
<span style="text-decoration: none;">.parent {<br> width:800px;<br> height:500px;<br> border:2px solid #000;<br> position:relative;<br> }<br> .child {<br> width:300px;<br> height:200px;<br> margin:auto;<br> position:absolute;/*设定水平和垂直偏移父元素的50%,再根据实际长度将子元素上左挪回一半大小*/<br> left:50%;<br> top:50%;<br> margin-left: -150px;<br> margin-top:-100px;<br> background-color: red;<br> }<br></span>
登录后复制
更多div在另一个div里垂直居中的示例介绍相关文章请关注PHP中文网!
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章
刺客信条阴影:贝壳谜语解决方案
1 个月前
By DDD
Windows 11 KB5054979中的新功能以及如何解决更新问题
3 周前
By DDD
在哪里可以找到原子中的起重机控制钥匙卡
1 个月前
By DDD
如何修复KB5055523无法在Windows 11中安装?
2 周前
By DDD
Inzoi:如何申请学校和大学
3 周前
By DDD

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

关于Flex布局中紫色斜线区域的疑问在使用Flex布局时,你可能会遇到一些令人困惑的现象,比如在开发者工具(d...
