大家好,欢迎来到IT知识分享网。
拓展一种居中用法,
(1)先定位,设置 top:0;bottom:0;margin:auto 可以使元素水平居中。
(2)设置 left:0;right:0;margin:auto 可以使元素垂直居中。
(3)设置四个值都是0,margin:auto ;这个元素就在正中间了。如果不设置元素大小,就平铺了。
<div class='outer'> <div class='inner'>88</div> </div>
.outer{ position: relative; height: 200px; background-color: green; } /*(1)水平居中,不设置宽度则会水平铺满父容器*/ .inner { background-color: red; position: absolute; left: 0; right: 0; width: 80px; margin: auto; } /*(2)垂直居中,不设置高度则会垂直铺满父容器*/ /* .inner { background-color: red; position: absolute; top: 0; bottom: 0; height: 100px; margin: auto; } */ /*(3)水平及垂直居中,不设置高度,宽度则会铺满父容器*/ /* .inner { background-color: red; position: absolute; left: 0; right: 0; top: 0; bottom: 0; width: 80px; height: 100px; margin: auto; } */
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/136511.html