css將兩個(gè)元素水平對(duì)齊的方法(兼容IE8)
發(fā)布時(shí)間:2018-09-06 15:19:58 作者:heath_learning
我要評(píng)論
這篇文章主要介紹了css將兩個(gè)元素水平對(duì)齊的方法(兼容IE8)的相關(guān)資料,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
css實(shí)現(xiàn)水平對(duì)齊,如圖

有人會(huì)說(shuō)css實(shí)現(xiàn)這種水平對(duì)齊要兼容ie8還不簡(jiǎn)單嗎?使用float: left,或者display: inline-block,不就可以了嗎?是的,最常用的最簡(jiǎn)單方式就是上面這兩種,但還有一種方式也可以實(shí)現(xiàn),那就是使用display: table-cell;
示例代碼
<style type="text/css">
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container{
width: 1000px;
height: 1000px;
margin: 100px;
background-color: #f60;
}
.left{
/*關(guān)鍵點(diǎn)在于將兩個(gè)元素設(shè)置為display:table-cell*/
display: table-cell;
vertical-align: top;
width: 20%;
min-width: 200px;
height: 400px;
background-color: #ccc;
}
.right{
display: table-cell;
vertical-align: top;
/*即使寬度設(shè)為2000px,元素的內(nèi)容還是可以正常顯示*/
width: 2000px;
height: 600px;
background-color: #f10;
}
</style>
<div class="container">
<div class="left">left</div>
<div class="right">right</div>
</div>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
- 在CSS中可以使用多種屬性來(lái)水平對(duì)齊元素,不過(guò)同時(shí)也要考慮一下覽器兼容性問(wèn)題,感興趣的朋友可以參考下2013-10-28
CSS教程:水平對(duì)齊(text-align)-CSS教程-網(wǎng)頁(yè)制作-網(wǎng)頁(yè)教學(xué)網(wǎng)
水平對(duì)齊(text-align),用以設(shè)定元素內(nèi)文本的水平對(duì)齊方式。 1.語(yǔ)法 text-align具體參數(shù)如下: 語(yǔ)法:text-align:left|right|center|justify 說(shuō)明:2008-10-17

