居中(css)

173 阅读1分钟

如何居中div

border: 1px solid red;
margin: 0 auto; 
height: 50px;
width: 80px;

如何居中一个浮动元素

浮动元素的上下左右居中:

border: 1px solid red;
float: left;
position:absolute;
width: 200px;
height: 100px;
left: 50%;
top: 50%;
margin: -50px 0 0 -100px;

如何让绝对定位的div居中

绝对定位的左右居中:

border: 1px solid black;
position: absolute;
width: 200px;
height: 100px;
margin: 0 auto;
left: 0;
right: 0;

flex 居中

 <div class="parent" style="
 display: flex;
 flex-direction: row;
 justify-content: center;
 width: 100%;
 height: 100%;
 ">
 <div class="child" style="
 width: 50%;
 "></div>
 </div>