標籤:嵌套 flow 沒有 清除 代碼 最簡 footer 網頁布局 相對
基礎知識-css第五天,今天學習了css主要知識浮動,和定位,都是關於網頁布局的。這個2塊知識用好了,後期做好看的動畫,布局就不成問題了。
浮動left
浮動的框可以向左或是向右移動,直到它的邊緣碰到包含框或是另個浮動框的邊框為止
特點設定了浮動的元素不佔原來的位置(不在標準流)可以讓區塊層級元素在一行顯示浮動可以行內元素為塊元素注意:轉化過程儘可能用display轉化 屬性值
清除浮動
額外標籤法
<style> outer{border:1px solid black; width:300} .inner{width:50px; height:50px; background-color:#ff4400; margin-right:20px; float:Left;} .footer{backgrtound:#005fc3;width:200px; height:50px;} .clearfix{clear:both()}</style><div class="outer"> <div class="inner"></div> <div class="inner"></div> <div class="inner"></div> <div class="clearfix"></div></div>//這是早期普遍使用的方法,但是對於有代碼潔癖的人來說,解決的不夠完美
注意:clear 屬性規定元素的哪一側不允許其他浮動元素。(屬性:left 左邊不出現浮動 \ right 在右側不出現浮動元素 \ both 左右倆側不出現浮動 \ none 預設值可以出現浮動 \ inherit 繼承父元素clear:inherit)
使用:after為元素
<style> outer{border:1px solid black; width:300} .inner{width:50px; height:50px; background-color:#ff4400; margin-right:20px; float:Left;} .footer{backgrtound:#005fc3;width:200px; height:50px;} .clearfix:after{ content:‘‘; display:block; clear:both;}//最簡單的方法 .clearfix(zoom:1;)//相容 ie</style><div class="outer clearfix"> <div class="inner"></div> <div class="inner"></div> <div class="inner"></div></div>
給父元素定高
<style> outer{border:1px solid black; width:300; height:500px;} .inner{width:50px; height:50px; background-color:#ff4400; margin-right:20px; float:Left;} .footer{backgrtound:#005fc3;width:200px; height:50px;}</style><div class="outer "> <div class="inner"></div> <div class="inner"></div> <div class="inner"></div></div>
利用overflow:hidden屬性
<style> outer{border:1px solid black; width:300; overflow:hidden; zoom:1;//相容IE} .inner{width:50px; height:50px; background-color:#ff4400; margin-right:20px; float:Left;} .footer{backgrtound:#005fc3;width:200px; height:50px;}</style><div class="outer "> <div class="inner"></div> <div class="inner"></div> <div class="inner"></div></div>
父級元素浮動
當父元素浮動的時候,無需為子項目的浮動或是清楚浮動,布局經常用到
<style> outer{border:1px solid black; width:300;float:left;} .inner{width:50px; height:50px; background-color:#ff4400; margin-right:20px; float:Left;} .footer{backgrtound:#005fc3;width:200px; height:50px;} .clearfix:after{content:‘‘; display:block; clear:both;} .clearfix{ zoom:1 }</style><div class="outer "> <div class="inner"></div> <div class="inner"></div> <div class="inner"></div></div><div class="clearfix"></div>
overflow的使用
如果內容溢出一個元素框,會發生的事
overflow設定捲軸
顯示捲軸
<div style="width:260px; height:120px; overflow:scroll;"></div>
上下,左右捲軸
<div style="width:260px; height:120px; overflow-y:scrll;"></div> overflow-x(左右捲軸)
css定位oosition
position:absolute 絕對位置 特點:1、當給一個單獨的元素設定絕對位置,以瀏覽器左上方為基準設定定位的 2、當盒子發生嵌套關係的時候,如果父盒子沒有設定定位,子盒子設定定位父盒子 左上方為基準設定定位。 3、當盒子發生嵌套關係的時候,如果盒子設定定位,子盒子設定定位父盒子左上方為基準設定定位。 4、給盒子設定絕對位置,該盒子不佔位置 5、給行內元素設定絕對位置後,改元素轉化為了行內塊元素注意:元素設定了絕對位置後,通過具體的方位名稱可以隨便設定元素的位置 position:relative 相對定位 特點:1、元素設定了相對定位後占原來的位置 2、設定相對定位以自己的位置為參照設定位置 3、相對定位不能進行元素的模式轉換
4、子絕父相(子項目設定絕對位置,父元素設定相對定位) position:fixed 固定定位 特點:1、固定定位不佔位置 2、將行內元素轉化為行內塊元素
第五天-css基礎(浮動 網頁布局 定位方式,清除定位)