三行並列,透視表列標籤並列

來源:互聯網
上載者:User

三行並列,透視表列標籤並列

1 <div class="content">2     <div class="left"></div>3     <div class="center"></div>4     <div class="right"></div>5 </div> 
1 body{margin:0;padding:0;}2 .content div{3      width:100px;4      height:100px;5      background:rgb(147,172,213);6      margin:10px;7 }

方法一:float

 1 .content div{float:left;} 

三個div一起浮動,浮動元素無外邊距合并問題,故center左右margin都是20px。

 方法二:絕對位置

1 .content {position:relative;}2 .content div{position:absolute;}3 div.center{top:0;left:110px;}4 div.right{top:0;left:220px;}  

設定父元素為relative,被定位的子項目為absolute,絕對位置不佔位空間,所以此時三個元素會重疊於父元素的頂點,再用top,left布局左右margin10px。

方法三:inline-block

  1 .content div{display:inline-block;} 

將其變為行內塊元素,但是這樣div之間會有額外間距,且相容問題較多。

方法四:margin負值

1  div.center{2       margin-left:120px;/*100+10*2=120px 以下數值都以center左右margin為10px考慮*/3       margin-top:-110px;/*100+10=110px 要想用margin-top實現上移,則其值為負*/4 }5 div.right{6       margin-left:230px;/*100*2+10*3=230px*/7       margin-top:-110px;/*當center上去之後,原佔位空間不存在,right上移,故再移動需要的高度與center一致為100+10=110px。而如果先寫right,margin-top就應該上移(100+10)*2=220px*/8 }

在網速較慢或者高頻率重新整理時,使用margin負值會出現明顯的移動,故此法不作推薦。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.