一、利用marginios
div {
width: 100px;
height: 100px;
background-color: skyblue;
position: absolute;
top: 50%;
left: 50%;
margin-top: -50px;
margin-left: -50px;
}
分析:orm
top: 50%; left: 50%;讓元素的左上在父元素中垂直水平居中
margin-top: -50px; margin-left: -50px;讓元素向上向右偏移自身一半的距離
二、利用translateget
div {
width: 100px;
height: 100px;
background-color: skyblue;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
分析:it
top: 50%; left: 50%;讓元素的左上在父元素中垂直水平居中
transform: translate(-50%, -50%);讓元素向上向右移動自身一半的距離
三、四個方位所有爲0,用margin定位io
div {
width: 100px;
height: 100px;
background-color: skyblue;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right : 0;
margin: auto;
}
分析:form
四個方位所有爲0時,相互抵消,盒子會在初始位置顯示
margin: auto;讓盒子垂直水平居中class
<div class="bottom_soft_link">
<a target="_blank" class="bottom_soft_link_ios" href="xxx.com" title="客戶端蘋果手機APP下載">iOS下載</a>
<a target="_blank" class="bottom_soft_link_ios" href="http://jinan.changtu.com/" title="濟南長途汽車總站電話">濟南長途汽車總站電話</a>
</div>transform