婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > html清除浮動的6種方法示例

html清除浮動的6種方法示例

熱門標簽:洛陽防封卡外呼系統廠家 山東電銷機器人軟件 常州電話外呼系統招商 成都企業外呼系統 智能語音電銷機器人客戶端 南通電銷外呼系統軟件 申請400電話移動 廣州防封電銷機器人廠家 上海400電話辦理到易號網

使用display:inline-block會出現的情況:

1.使塊元素在一行顯示
2.使內嵌支持寬高
3.換行被解析了
4.不設置的時候寬度由內容撐開
5.在IE6,7下步支持塊標簽

由于inline-block屬性換行的時候被解析(有間隙)故解決方法使用浮動float:left/right

使用浮動時出現的情況:

1.使塊元素在一行顯示
2.使內嵌元素支持寬高
3.不設置不寬高的時候寬度由內容撐開
4.換行不被解析(故使用行內元素的時候清除間隙的方法可以使用浮動)
5.元素添加浮動,會脫離文檔流,按照指定的一個方向移動,直到碰到父級的邊界或者另一個浮動元素停止(文檔流是文檔中可顯示對象在排列時所占用的位置)

復制代碼 代碼如下:

!DOCTYPE HTML>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=utf-8">
title>無標題文檔/title>
style>
div,span{height:100px;background:red;border:1px solid #000; float:left;}
/*
inline-block
1.使塊元素在一行顯示
2.使內嵌支持寬高
3.換行被解析了
4.不設置寬度的時候寬度由內容撐開
5.在IE6,7下不支持塊標簽
浮動:
1.使塊元素在一行顯示
2.使內嵌支持寬高
3.不設置寬度的時候寬度由內容撐開
*/
/style>
/head>
body>
div class="div1">div1/div>
div class="div2">div2/div>
span class="span1">span1/span>
span class="span2">span2/span>
/body>
/html>


下面的代碼只有box1浮動,則box1,box2重疊一起。兩者都浮動就不會重疊

復制代碼 代碼如下:

!DOCTYPE HTML>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=utf-8">
title>無標題文檔/title>
style>
.box1{ width:100px;height:100px;background:red; float:left;}
.box2{ width:200px;height:200px;background:blue; /* float:left;*/}
/style>
/head>
body>
div class="box1">/div>
div class="box2">/div>
/body>
/html>

清浮動的方法:
1.給父級也加浮動
(這種情況當父級margin:0 auto;時不居中)

復制代碼 代碼如下:

!DOCTYPE HTML>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=utf-8">
title>無標題文檔/title>
style>
.box{ width:300px;margin:0 auto;border:10px solid #000; float:left;}
.div{ width:200px;height:200px;background:red;float:left;}
/*
    清浮動
    1.給父級也加浮動(不居中了)
*/
/style>
/head>
body>
div class="box">
    div class="div">/div>
/div>
/body>
/html>


2.給父級加display:inline-block;(同方法1,不居中。只有IE6,7居中)

復制代碼 代碼如下:

!DOCTYPE HTML>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=utf-8">
title>無標題文檔/title>
style>
.box{ width:300px;margin:0 auto;border:10px solid #000; display:inline-block;}
.div{ width:200px;height:200px;background:red;float:left;}
/*
    清浮動
    1.給父級也加浮動
    2.給父級加display:inline-block
*/
/style>
/head>
body>
div class="box">
    div class="div">/div>
/div>
/body>
/html>


3.在浮動元素下加div class="clear">/div>

  .clear{ height:0px;font-size:0;clear:both;}但是在ie6下,塊元素有最小高度,即當height19px時,默認為19px,解決方法:font-size:0;或overflow:hidden;
復制代碼 代碼如下:

!DOCTYPE HTML>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=utf-8">
title>無標題文檔/title>
style>
.box{ width:300px;margin:0 auto;border:10px solid #000;}
.div{ width:200px;height:200px;background:red;float:left;}
.clear{ height:0px;font-size:0;clear:both;}
/*
    清浮動
    1.給父級也加浮動
    2.給父級加display:inline-block
    3.在浮動元素下加div class="clear">/div>
    .clear{ height:0px;font-size:0;clear:both;}
*/
/style>
/head>
body>
div class="box">
    div class="div">/div>
        div class="clear">/div>
/div>
/body>
/html>

4.在浮動元素下加br clear="all">
復制代碼 代碼如下:

!DOCTYPE HTML>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=utf-8">
title>無標題文檔/title>
style>
.box{ width:300px;margin:0 auto;border:10px solid #000;}
.div{ width:200px;height:200px;background:red;float:left;}
/*
    清浮動
    1.給父級也加浮動
    2.給父級加display:inline-block
    3.在浮動元素下加div class="clear">/div>
    .clear{ height:0px;font-size:0;clear:both;}
    4.在浮動元素下加br clear="all"/>
*/
/style>
/head>
body>
div class="box">
    div class="div">/div>
    br clear="all"/>
/div>
/body>
/html>

5.給浮動元素父級加{zoom:1;}
:after{content:""; display:block;clear:both;}
復制代碼 代碼如下:

!DOCTYPE HTML>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=utf-8">
title>無標題文檔/title>
style>
.box{margin:0 auto;border:10px solid #000;}
.div{ width:200px;height:200px;background:red;float:left;}
.clear{zoom:1;}
.clear:after{content:""; display:block;clear:both;}
/*
    清浮動
    1.給父級也加浮動
    2.給父級加display:inline-block
    3.在浮動元素下加div class="clear">/div>
    .clear{ height:0px;font-size:0;clear:both;}
    4.在浮動元素下加br clear="all"/>

    5. 給浮動元素的父級加{zoom:1;}
    :after{content:""; display:block;clear:both;}

    **在IE6,7下浮動元素的父級有寬度就不用清浮動

    haslayout 根據元素內容的大小 或者父級的父級的大小來重新的計算元素的寬高

  display: inline-block
  height: (任何值除了auto)
  float: (left 或 right)
  width: (任何值除了auto)
  zoom: (除 normal 外任意值)
*/
/style>
/head>
body>
div class="box clear">
    div class="div">/div>
/div>
/body>
/html>

6.給浮動元素父級加overflow:auto;
復制代碼 代碼如下:

!DOCTYPE HTML>
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=utf-8">
title>無標題文檔/title>
style>
.box{ width:300px;border:1px solid #000;overflow:auto;}
.div1{ width:260px;height:400px;background:Red;float:left;}
/style>
/head>
body>
div class="box">
    div class="div1">/div>
/div>
/body>
/html>

您可能感興趣的文章:
  • CSS清除浮動常用方法小結
  • css別忘記清除浮動clear:both
  • 對于IE7、FF、OP清除浮動的最優方法
  • 一個老外弄的Clearing floats(清除浮動的方法)

標簽:混顯 滄州 貴州 萊蕪 鶴壁 廣安 邵陽 賀州

巨人網絡通訊聲明:本文標題《html清除浮動的6種方法示例》,本文關鍵詞  html,清除,浮動,的,6種,方法,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《html清除浮動的6種方法示例》相關的同類信息!
  • 本頁收集關于html清除浮動的6種方法示例的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 托克托县| 江山市| 怀远县| 潞城市| 景泰县| 缙云县| 湘西| 贺州市| 射阳县| 屏东市| 安顺市| 任丘市| 宁远县| 文昌市| 镶黄旗| 含山县| 信宜市| 桂阳县| 肥西县| 枣强县| 柞水县| 山东省| 龙游县| 兰州市| 方城县| 桦甸市| 改则县| 出国| 廉江市| 共和县| 嵊泗县| 汽车| 武安市| 佛教| 炎陵县| 资溪县| 辽阳市| 大港区| 阳春市| 盘锦市| 阿图什市|