css让容器水平垂直居中的7种方式
<div class="center"></div> </div>
CSS Code复制内容到剪贴板
/* css */ .wrap { background: yellow; width: 200px; height: 200px; display: flex; align-items: center; justify-content: center; } .center { background: green; width: 100px; height: 100px; }
移动端首选 方法五:display:flex;margin:auto
XML/HTML Code复制内容到剪贴板
<!-- html --> <div class="wrap"> <div class="center"></div> </div>
CSS Code复制内容到剪贴板
/* css */ .wrap { background: yellow; width: 200px; height: 200px; display: flex; } .center { background: green; width: 100px; height: 100px; margin: auto; }
移动端首选 方法六:纯position
XML/HTML Code复制内容到剪贴板
<!-- html --> <div class="wrap"> <div class="center"></div> </div>
CSS Code复制内容到剪贴板
/* css */ .wrap { background: yellow; width: 200px; height: 200px; position: relative; (编辑:晋中站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |