-
FLOAT
(css屬性)
鎖定
- 中文名
- 浮動
- 外文名
- float
- 意 思
- 元素浮動
- 用 途
- 網頁排版
FLOAT性質
FLOAT瀏覽器支持
所有主流瀏覽器都支持 float 屬性。
FLOAT定義
float 屬性定義元素在哪個方向浮動。以往這個屬性總應用於圖像,使文本圍繞在圖像周圍,不過在 CSS 中,任何元素都可以浮動。浮動元素會生成一個塊級框,而不論它本身是何種元素。
如果浮動非替換元素,則要指定一個明確的寬度;否則,它們會盡可能地窄。
默認值:none;
繼承性:no;
版本:CSS
可能的值
值 | 描述 |
---|---|
left | 元素向左浮動。 |
right | 元素向右浮動。 |
none | 默認值。元素不浮動,並會顯示在其在文本中出現的位置。 |
inherit | 規定應該從父元素繼承 float 屬性的值。 |
FLOAT實例
FLOAT創建無表格的首頁
使用浮動來創建擁有頁眉、頁腳、左側目錄和主體內容的首頁。
<html> <head> <style type="text/css"> div.container { width:100%; margin:0px; border:1px solid gray; line-height:150%; } div.header,div.footer { padding:0.5em; color:white; background-color:gray; clear:left; } h1.header { padding:0; margin:0; } div.left { float:left; width:160px; margin:0; padding:1em; } div.content { margin-left:190px; border-left:1px solid gray; padding:1em; } </style> </head> <body> <div class="container"> <div class="header"><h1 class="header">W3School.com.cn</h1></div> <div class="left"><p>"Never increase, beyond what is necessary, the number of entities required to explain anything." William of Ockham (1285-1349)</p></div> <div class="content"> <h2>Free Web Building Tutorials</h2> <p>At W3School.com.cn you will find all the Web-building tutorials you need, from basic HTML and XHTML to advanced XML, XSL, Multimedia and WAP.</p> <p>W3School.com.cn - The Largest Web Developers Site On The Net!</p></div> <div class="footer">Copyright 2008 by YingKe Investment.</div> </div> </body> </html>
FLOAT創建水平菜單
使用具有一欄超鏈接的浮動來創建水平菜單。
<html> <head> <style type="text/css"> ul { float:left; width:100%; padding:0; margin:0; list-style-type:none; } a { float:left; width:7em; text-decoration:none; color:white; background-color:purple; padding:0.2em 0.6em; border-right:1px solid white; } a:hover {background-color:#ff3300} li {display:inline} </style> </head> <body> <ul> <li><a href="#">Link one</a></li> <li><a href="#">Link two</a></li> <li><a href="#">Link three</a></li> <li><a href="#">Link four</a></li> </ul> <p> 在上面的例子中,我們把 ul 元素和 a 元素浮向左浮動。li 元素顯示為行內元素(元素前後沒有換行)。這樣就可以使列表排列成一行。ul 元素的寬度是 100%,列表中的每個超鏈接的寬度是 7em(當前字體尺寸的 7 倍)。我們添加了顏色和邊框,以使其更漂亮。 </p> </body> </html>
FLOAT段落的首字母浮動於左側
<html> <head> <meta charset="utf-8"> <style> span { float:left; width:1.2em; font-size:400%; font-family:algerian,courier; line-height:80%; } </style> </head> <body> <p> <span>這</span>是一些文本。 這是一些文本。這是一些文本。 這是一些文本。這是一些文本。這是一些文本。 這是一些文本。這是一些文本。這是一些文本。 這是一些文本。這是一些文本。這是一些文本。 這是一些文本。這是一些文本。這是一些文本。 這是一些文本。這是一些文本。這是一些文本。 這是一些文本。這是一些文本。這是一些文本。 </p> </body> </html>
在該示例的段落中, 第一個字嵌入在span元素中,這個span元素的寬度是當前字體大小的1.2倍,這個span元素是當前字體的400%(相當大), line-height 為80%,文字的字體為"Algerian"。
- 參考資料
-
- 1. CSS float 屬性 .w3school[引用日期2014-04-10]
- 2. CSS float .W3Cschool[引用日期2018-04-23]
- 詞條統計
-
- 瀏覽次數:次
- 編輯次數:9次歷史版本
- 最近更新: canguanxihu