標籤:osi 顯示 批評 alt sts 文檔流 south png com
所示的布局設計是很常見的。這個該怎麼做呢?
技術需求:header 要固定住在頂部,不隨滑鼠滾動而向上移動;左邊的div的有一定的寬度,但是要貼瀏覽器的底部(螢幕頂部);右邊的dv要佔據右邊的全屏。
好。咱們來寫這個:
HTML結構:
<header>header</header><section> <div class="left">left</div> <div class="right">right</div></section>
css:
header {
width: 100%;
height:30px;
background-color: #ddd;
position: fixed;
top:0px;
}
.left {
width: 200px;
height: 100%;
position: fixed;
left: 0;
top: 0;
background-color: #000;
margin-top: 30px;
}
.right {
margin-top: 30px;
margin-left:200px;
width: 100%;
height: 500px;
background-color: red;
}
css解釋一下:
header採用定位的模式,定位元模式為固定定位,top為0,就定在頂部的位置不動,.left 的定位元模式也是固定定位,高度是100%,也就是整個螢幕的高度,因為頂部的header的是固定定位的,脫離文檔流了,因此,它下面的元素會頂上去,因此,需要有一個margin-top的設定,值就是header的高度,後面的.right一樣,也需要有一個margin-top的設定。,但是還有一個重要的點,下面的元素因為上面的元素的固定定位,導致下面會頂到上面的位置,同理,左邊的固定定位也會上右邊的元素會擠到左邊來,因此也需要一個margin-left的值。注意:.left的值是有一定元素高度的,如果元素的高度超過螢幕的高度,就會不顯示,如果要他們顯示的話,就需要設定overflow-y:auto。我想我解釋清楚了,如果有錯誤之處,敬請批評指出。
每日一句:China is expanding its presence in the South China Sea with plans to build an underwater observation system and to send tourists to the disputed areas.
翻譯:
中國正在擴大其在南中國海有計劃建立一個水下觀測系統和送遊客到有爭議的地區。
html的結構-廠子型的布局