css+html簡單布局demo

來源:互聯網
上載者:User

標籤:布局   介面   html   css   



         在html中引入css樣式,可以改變html的塊布局方式,使得介面的布局更加美觀。接下來看一個基礎布局的小例子:



       

<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>margin布局</title></head><style type="text/css">#container{width: 1002px;background: gray;}#header{height: 120px;background: orange;}#main{background: green;height: 600px;}#lside{width: 700px;height: 600px;float: left;background: pink;}.four{width: 130px;height: 280px;float: left;margin: 10px;background: black;}#rside{width: 302px;height: 600px;background: purple;float: right;}#footer{height: 120px;background: blue;}</style><body><div id="container"><div id="header"></div><div id="main"><div id="lside"><div class="four"></div><div class="four"></div><div class="four"></div><div class="four"></div></div><div id="rside"></div></div><div id="footer"></div></div></body></html>


  效果如下:


 

 


        在上面的布局中,我們主要使用margin屬性來對div進行布局,在實際中,感覺margin屬性主要適用於塊與塊之間的布局,當我們要對盒子中的內容進行布局的時候,我們可以使用盒子的另一個屬性:padding,這個屬性可以布局盒子內部的距離:

    

           例如,我們加入padding屬性,並在四個div中加入一些文字內容:


    



      :


     

   


         注意,這裡在實際做的時候,因為加入了padding值,導致了div最後不能並排顯示在父div中,這裡還修改了div的寬度值,使第四個div不至於被擠到下面去。

  

          感覺加入css樣式後,最近做的小demo跟以前只用html做的demo比起來,不僅布局上更加靈活多變,而且樣式設定也比較簡單了。


      






css+html簡單布局demo

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.