通過使用框架,你可以在同一個瀏覽器窗口中顯示不止一個頁面。每份HTML文檔稱為一個框架,并且每個框架都獨立于其他的框架。
使用框架的壞處:
框架結構標簽(<frameset>)
Frame 標簽定義了放置在每個框架中的 HTML 文檔。
在下面的這個例子中,我們設置了一個兩列的框架集。第一列被設置為占據瀏覽器窗口的 25%。第二列被設置為占據瀏覽器窗口的 75%。HTML 文檔 "frame_a.htm" 被置于第一個列中,而 HTML 文檔 "frame_b.htm" 被置于第二個列中:
<html> <frameset cols="25%,75%"> <frame src="/example/html/frame_a.html"> <frame src="/example/html/frame_b.html"> </frameset> </html>
HTML基礎教程:框架基礎
頁布局對改善網站的外觀非常重要。
請慎重設計您的網頁布局。
實例
使用 <div> 元素的網頁布局
[demo]
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
div#container{width:500px}
div#header {background-color:#99bbbb;}
div#menu {background-color:#ffff99;height:200px;width:150px;float:left;}
div#content {background-color:#EEEEEE;height:200px;width:350px;float:left;}
div#footer {background-color:#99bbbb;clear:both;text-align:center;}
h1 {margin-bottom:0;}
h2 {margin-bottom:0;font-size:18px;}
ul {margin:0;}
li {list-style:none;}
</style>
</head>
<body>
<div id="container">
<div id="header">
<h1>Main Title of Web Page</h1>
</div>
<div id="menu">
<h2>Menu</h2>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
</div>
<div id="content">Content goes here</div>
<div id="footer">Copyright W3School.com.cn</div>
</div>
</body>
</html>
[/demo]
如何使用 <div> 元素添加布局。
使用 <table> 元素的網頁布局
[demo]
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<table width="500" border="0">
<tr>
<td colspan="2" style="background-color:#99bbbb;">
<h1>Main Title of Web Page</h1>
</td>
</tr>
<tr valign="top">
<td style="background-color:#ffff99;width:100px;text-align:top;">
<b>Menu</b><br />
HTML<br />
CSS<br />
JavaScript
</td>
<td style="background-color:#EEEEEE;height:200px;width:400px;text-align:top;">
Content goes here</td>
</tr>
<tr>
<td colspan="2" style="background-color:#99bbbb;text-align:center;">
Copyright W3School.com.cn</td>
</tr>
</table>
</body>
</html>
[/demo]
如何使用 <table> 元素添加布局。
網站布局
大多數網站會把內容安排到多個列中(就像雜志或報紙那樣)。
可以使用 <div> 或者 <table> 元素來創建多列。CSS 用于對元素進行定位,或者為頁面創建背景以及色彩豐富的外觀。
提示:即使可以使用 HTML 表格來創建漂亮的布局,但設計表格的目的是呈現表格化數據 - 表格不是布局工具!
HTML 布局 - 使用 <div> 元素
div 元素是用于分組 HTML 元素的塊級元素。
下面的例子使用五個 div 元素來創建多列布局:
實例
[demo]
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
div#container{width:500px}
div#header {background-color:#99bbbb;}
div#menu {background-color:#ffff99; height:200px; width:100px; float:left;}
div#content {background-color:#EEEEEE; height:200px; width:400px; float:left;}
div#footer {background-color:#99bbbb; clear:both; text-align:center;}
h1 {margin-bottom:0;}
h2 {margin-bottom:0; font-size:14px;}
ul {margin:0;}
li {list-style:none;}
</style>
</head>
<body>
<div id="container">
<div id="header">
<h1>Main Title of Web Page</h1>
</div>
<div id="menu">
<h2>Menu</h2>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
</div>
<div id="content">Content goes here</div>
<div id="footer">Copyright W3School.com.cn</div>
</div>
</body>
</html>
[/demo]
上面的 HTML 代碼會產生如下結果:
使用 div 和 CSS 進行布局
HTML 布局 - 使用表格
使用 HTML <table> 標簽是創建布局的一種簡單的方式。
可以使用 <div> 或者 <table> 元素來創建多列。CSS 用于對元素進行定位,或者為頁面創建背景以及色彩豐富的外觀。
提示:即使可以使用 HTML 表格來創建漂亮的布局,但設計表格的目的是呈現表格化數據 - 表格不是布局工具!
下面的例子使用三行兩列的表格 - 第一和最后一行使用 colspan 屬性來橫跨兩列:
實例
[demo]
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<table width="500" border="0">
<tr>
<td colspan="2" style="background-color:#99bbbb;">
<h1>Main Title of Web Page</h1>
</td>
</tr>
<tr valign="top">
<td style="background-color:#ffff99;width:100px;text-align:top;">
<b>Menu</b><br />
HTML<br />
CSS<br />
JavaScript
</td>
<td style="background-color:#EEEEEE;height:200px;width:400px;text-align:top;">
Content goes here</td>
</tr>
<tr>
<td colspan="2" style="background-color:#99bbbb;text-align:center;">
Copyright W3School.com.cn</td>
</tr>
</table>
</body>
</html>
[/demo]
上面的 HTML 代碼會產生以下結果:
使用表格進行布局
HTML 布局 - 有用的提示
提示:使用 CSS 最大的好處是,如果把 CSS 代碼存放到外部樣式表中,那么站點會更易于維護。通過編輯單一的文件,就可以改變所有頁面的布局。如需學習更多有關 CSS 的知識,請訪問我們的 CSS 教程。
提示:由于創建高級的布局非常耗時,使用模板是一個快速的選項。通過搜索引擎可以找到很多免費的網站模板(您可以使用這些預先構建好的網站布局,并優化它們)。
HTML 布局標簽
標簽 描述
<div> 定義文檔中的分區或節(division/section)。
<span> 定義 span,用來組合文檔中的行內元素。
通過使用框架,你可以在同一個瀏覽器窗口中顯示不止一個頁面。
實例
垂直框架
[demo]
<html>
<frameset cols="25%,50%,25%">
<frame src="/example/html/frame_a.html">
<frame src="/example/html/frame_b.html">
<frame src="/example/html/frame_c.html">
</frameset>
</html>
[/demo]
本例演示:如何使用三份不同的文檔制作一個垂直框架。
水平框架
[demo]
<html>
<frameset rows="25%,50%,25%">
<frame src="/example/html/frame_a.html">
<frame src="/example/html/frame_b.html">
<frame src="/example/html/frame_c.html">
</frameset>
</html>
[/demo]
本例演示:如何使用三份不同的文檔制作一個水平框架。
框架
通過使用框架,你可以在同一個瀏覽器窗口中顯示不止一個頁面。每份HTML文檔稱為一個框架,并且每個框架都獨立于其他的框架。
使用框架的壞處:
開發人員必須同時跟蹤更多的HTML文檔
很難打印整張頁面
框架結構標簽(<frameset>)
框架結構標簽(<frameset>)定義如何將窗口分割為框架
每個 frameset 定義了一系列行或列
rows/columns 的值規定了每行或每列占據屏幕的面積
編者注:frameset 標簽也被某些文章和書籍譯為框架集。
框架標簽(Frame)
Frame 標簽定義了放置在每個框架中的 HTML 文檔。
在下面的這個例子中,我們設置了一個兩列的框架集。第一列被設置為占據瀏覽器窗口的 25%。第二列被設置為占據瀏覽器窗口的 75%。HTML 文檔 "frame_a.htm" 被置于第一個列中,而 HTML 文檔 "frame_b.htm" 被置于第二個列中:
<frameset cols="25%,75%">
<frame src="frame_a.htm">
<frame src="frame_b.htm">
</frameset>
基本的注意事項 - 有用的提示:
假如一個框架有可見邊框,用戶可以拖動邊框來改變它的大小。為了避免這種情況發生,可以在 <frame> 標簽中加入:noresize="noresize"。
為不支持框架的瀏覽器添加 <noframes> 標簽。
重要提示:不能將 <body></body> 標簽與 <frameset></frameset> 標簽同時使用!不過,假如你添加包含一段文本的 <noframes> 標簽,就必須將這段文字嵌套于 <body></body> 標簽內。(在下面的第一個實例中,可以查看它是如何實現的。)
更多實例
如何使用 <noframes> 標簽
[demo]
<html>
<frameset cols="25%,50%,25%">
<frame src="/example/html/frame_a.html">
<frame src="/example/html/frame_b.html">
<frame src="/example/html/frame_c.html">
<noframes>
<body>您的瀏覽器無法處理框架!</body>
</noframes>
</frameset>
</html>
[/demo]
本例演示:如何使用 <noframes> 標簽。
混合框架結構
[demo]
<html>
<frameset rows="50%,50%">
<frame src="/example/html/frame_a.html">
<frameset cols="25%,75%">
<frame src="/example/html/frame_b.html">
<frame src="/example/html/frame_c.html">
</frameset>
</frameset>
</html>
[/demo]
本例演示如何制作含有三份文檔的框架結構,同時將他們混合置于行和列之中。
含有 noresize="noresize" 屬性的框架結構
[demo]
<html>
<frameset cols="50%,*,25%">
<frame src="/example/html/frame_a.html" noresize="noresize" />
<frame src="/example/html/frame_b.html" />
<frame src="/example/html/frame_c.html" />
</frameset>
</html>
[/demo]
本例演示 noresize 屬性。在本例中,框架是不可調整尺寸的。在框架間的邊框上拖動鼠標,你會發現邊框是無法移動的。
導航框架
[demo]
<html>
<frameset cols="120,*">
<frame src="/example/html/html_contents.html">
<frame src="/example/html/frame_a.html" name="showframe">
</frameset>
</html>
[/demo]
本例演示如何制作導航框架。導航框架包含一個將第二個框架作為目標的鏈接列表。名為 "contents.htm" 的文件包含三個鏈接。
內聯框架
[demo]
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<iframe src="./imagecopy1234567890/test.jpg"></iframe>
<p>一些老的瀏覽器不支持 iframe。</p>
<p>如果得不到支持,iframe 是不可見的。</p>
</body>
</html>
[/demo]
本例演示如何創建內聯框架(HTML 頁中的框架)。
跳轉至框架內的一個指定的節
[demo]
<html>
<frameset cols="20%,80%">
<frame src="/example/html/frame_a.html">
<frame src="/example/html/link.html#C10">
</frameset>
</html>
[/demo]
本例演示兩個框架。其中的一個框架設置了指向另一個文件內指定的節的鏈接。這個"link.htm"文件內指定的節使用 <a name="C10"> 進行標識。
使用框架導航跳轉至指定的節
[demo]
<html>
<frameset cols="180,*">
<frame src="/example/html/content.html">
<frame src="/example/html/link.html" name="showframe">
</frameset>
</html>
[/demo]
本例演示兩個框架。左側的導航框架包含了一個鏈接列表,這些鏈接將第二個框架作為目標。第二個框架顯示被鏈接的文檔。導航框架其中的鏈接指向目標文件中指定的節。
果如圖:
代碼如下:
index.html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>css垂直菜單欄</title> <link rel="stylesheet" href="index.css" media="screen" type="text/css" /> </head> <body> <div id="container"> <div style="text-align:center;clear:both;"> </div> <div class="tab-container"> <div id="c1"> <a href="#c1" title="First">First</a> <div class="tab-content"> <h3>First</h3> </div> </div> <div id="c2"> <a href="#c2" title="Second">Second</a> <div class="tab-content"> <h3>Second</h3> </div> </div> <div id="c3"> <a href="#c3" title="Third">Third</a> <div class="tab-content"> <h3>Third</h3> </div> </div> <div id="c4"> <a href="#c4" title="Fourth">Fourth</a> <div class="tab-content"> <h3>Fourth</h3> </div> </div> </div> </div> </body> </html>
index.css
body { line-height:1; font-size:13px; font-family:Arial, Helvetica, sans-serif; } p, .tab-content li, h1, h2, h3{ margin-bottom: 10px; } .tab-container h3{ font-size:147%; } #container{ margin: 0 auto; margin-top: 4%; } .tab-container { position: relative; width: 100%; z-index: 0; } .tab-container > div { } .tab-container > div > a { position: relative !important; display: inline-block; font-size: 15px; font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; font-weight: bold; text-transform: uppercase; margin: 1px; background: #ddd; padding: 20px 55px; -moz-border-radius: 3px; -webkit-border-radius: 0px; border-radius: 3px; -moz-box-shadow: 0 4px 10px -5px #000000; box-shadow: 0 4px 10px -5px #000000; -webkit-box-shadow: 0 4px 10px -5px #000000; width: 50px; height: 10px; text-decoration: none; } .tab-container > div:not(:target) > a { } .tab-container > div:target > a { background: none repeat scroll 0 0 #948a81; text-shadow: 0 1px 0 #4C4648; } .tab-container > div > div { background: #ddd; top: 0; padding: 20px; min-height: 250px; position: absolute; left: 180px; width: 400px; } .tab-container > div:target > div { position: absolute; z-index: 3 !important; }
內容來自作者csdn博客號
*請認真填寫需求信息,我們會在24小時內與您取得聯系。