第27章 CSS傳統布局(上)

來源:互聯網
上載者:User

標籤:

第 27章 CSS傳統布局[上]
學習要點:
1.布局模型
2.表格版面配置
3.浮動布局

本章主要探討 HTML5中 CSS早期所使用的傳統布局,很多情況下,這些布局方式還
是非常有用的。
一.布局模型
在早期沒有平板和智能手機等行動裝置大行其道的時期,Web頁面的設計主要是面向
PC端電腦解析度展開的。這種解析度比例比較單一,基本上只要滿足最低解析度設計即可。
一般來說有 4:3、16:10、16:9這樣的主要解析度。那麼,從這種比例上來看,長度總是
大於寬度的。從最低解析度 1024 * 768設計即可。為了使瀏覽器底部不出現捲軸,需要
減去適當的寬度,比如減去 28,最終固定長度設定為 996即可。當然,也有一些網站在近
兩年講最低解析度設定為 1280減去捲軸寬度,因為大顯示器逐步主流。
除了剛才所說的固定長度的布局,還有一種是流體布局,就是布局的長度為百分比,比
如 100%。不管你是什麼解析度,它都能全螢幕顯示,當然,局限性也特別大,只適合一些單
一頁面,複雜的頁面,會隨著不同瀏覽器產生各種閱讀障礙。


二.表格版面配置
表格版面配置,就是通過設定固定的儲存格,去除表格邊框和填充實現的布局。當然這個布
局非常不建議使用,只是教學瞭解。表格應該用它最為語義的地方,就是二維表的資料顯示。
1.固定式配置
//HTML部分
<table border="0">
<tr>
<td colspan="2" class="header">header</td>
</tr>
<tr>
<td class="aside">aside</td>
<td class="section">section</td>
</tr>
<tr>
<td colspan="2" class="footer">footer</td>
</tr>
</table>
//CSS部分
body {
margin:0;
}
table {
margin:0 auto;
width: 960px;
border-spacing: 0;
}
.header {
height: 120px;
background-color: olive;
}
.aside {
width: 200px;
height: 500px;
background-color: purple;
}
.section {
width: 760px;
height: 500px;
background-color: maroon;
}



.footer {
height: 120px;
background-color: gray;
}
2.流體布局
表格的固定式配置改成流體布局非常簡單,只需要設定 table為 100%即可。
//修改 table
table {
width: 100%;
}
三.浮動布局
浮動布局主要採用 float和 clear兩個屬性來構建。
1.固定式配置
//HTML部分
<header>
header
</header>
<aside>
aside
</aside>
<section>
section
</section>
<footer>
footer
</footer>
//CSS部分
body {
width: 960px;
margin: 0 auto;
color: white;
}
header {
height: 120px;
background-color: olive;
}
aside {



width: 200px;
height: 500px;
background-color: purple;
float: left;
}
section {
width: 760px;
height: 500px;
background-color: maroon;
float:right;
}
footer {
height: 120px;
background-color: gray;
clear:both;
}


2.流體布局
流體布局只要更改 body元素的限定長度為 auto或 100%。然後左右兩列分別設定 20%
和 80%即可。
//CSS部分
body {
width: auto;
}
aside {
width: 20%;
}
section {
width: 80%;
}

 

 

例子:

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<title>CSS傳統布局[上]</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

<table border="0">
<tr>
<td colspan="2" class="header">header</td>
</tr>
<tr>
<td class="aside">aside</td>
<td class="section">section</td>
</tr>
<tr>
<td colspan="2" class="footer">footer</td>
</tr>
</table>

</body>
</html>

 

 

@charset "utf-8";

body {
margin: 0;
}

table {
/*width: 960px;*/
width: 100%;
margin: 0 auto;
/*border-spacing: 0px;*/
border-collapse: collapse;
}
.header {
height: 120px;
background-color: olive;
}
.aside {
width: 200px;
height: 500px;
background-color: purple;
}
.section {
width: 760px;
background-color: maroon;
}
.footer {
height: 120px;
background-color: gray;
}

 

 

 

例子2

 

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<title>CSS傳統布局[上]</title>
<link rel="stylesheet" type="text/css" href="style2.css">
</head>
<body>

<header>
header
</header>

<aside>
aside
</aside>

<section>
section
</section>

<footer>
footer
</footer>

</body>
</html>

 

 

@charset "utf-8";

body {
margin: 0 auto;
/*width: 960px;*/
width: auto;
}

header {
height: 120px;
background-color: olive;
}
aside {
/*width: 200px;*/
width: 20%;
/*min-width: 120px;*/
height: 500px;
background-color: purple;
float: left;
}
section {
/*width: 760px;*/
width: 80%;
height: 500px;
background-color: maroon;
float: right;
}
footer {
height: 120px;
background-color: gray;
clear: both;
}

第27章 CSS傳統布局(上)

聯繫我們

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