<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    經(jīng)驗(yàn)不在于年限,在于積累---專(zhuān)注互聯(lián)網(wǎng)軟件開(kāi)發(fā)

    把工作當(dāng)事業(yè)做,把項(xiàng)目當(dāng)作品做!

      BlogJava :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
      55 Posts :: 0 Stories :: 66 Comments :: 0 Trackbacks
    CSS布局常用的方法:float:none|left|right 
    取值:
    none: 默認(rèn)值。對(duì)象不飄浮
    left: 文本流向?qū)ο蟮挠疫?br /> right: 文本流向?qū)ο蟮淖筮?nbsp;

    它是怎樣工作的,看個(gè)一行兩列的例子 
    xhtml:
    <div id="wrap">
    <div id="column1">這里是第一列</div>
    <div id="column2">這里是第二列</div>
    <div class="clear"></div> /*這是違背web標(biāo)準(zhǔn)意圖的,只是想說(shuō)明在它下面的元素需要清除浮動(dòng)*/
    </div> 
    CSS:
    #wrap{width:100;height:auto;}
    #column1{float:left;width:40;}
    #column2{float:right;width:60;}
    .clear{clear:both;}

    position:static|absolute|fixed|relative
    取值:
    static: 默認(rèn)值。無(wú)特殊定位,對(duì)象遵循HTML定位規(guī)則
    absolute: 將對(duì)象從文檔流中拖出,使用leftright,top,bottom等屬性相對(duì)于其最接近的一個(gè)最有定位設(shè)置的父對(duì)象進(jìn)行絕對(duì)定位。如果不存在這樣的父對(duì)象,則依據(jù)body對(duì)象。而其層疊通過(guò)z-index屬性定義
    fixed: 未支持。對(duì)象定位遵從絕對(duì)(absolute)方式。但是要遵守一些規(guī)范
    relative: 對(duì)象不可層疊,但將依據(jù)leftright,top,bottom等屬性在正常文檔流中偏移位置 

    它來(lái)實(shí)現(xiàn)一行兩列的例子 
    xhtml:
    <div id="wrap">
    <div id="column1">這里是第一列</div>
    <div id="column2">這里是第二列</div>
    </div> 
    CSS:
    #wrap{position:relative;/*相對(duì)定位*/width:770px;}
    #column1{position:absolute;top:0;left:0;width:300px;}
    #column2{position:absolute;top:0;right:0;width:470px;} 
    他們的區(qū)別在哪? 
    顯然,float是相對(duì)定位的,會(huì)隨著瀏覽器的大小和分辨率的變化而改變,而position就不行了,所以一般情況下還是float布局!

    CSS常用布局實(shí)例

    單行一列
    body{margin:0px;padding:0px;text-align:center;}
    #content{margin-left:auto;margin-right:auto;width:400px;} 

    兩行一列 
    body{margin:0px;padding:0px;text-align:center;}
    #content-top{margin-left:auto;margin-right:auto;width:400px;}
    #content-end{margin-left:auto;margin-right:auto;width:400px;} 

    三行一列 
    body{margin:0px;padding:0px;text-align:center;}
    #content-top{margin-left:auto;margin-right:auto;width:400px;width:370px;}
    #content-mid{margin-left:auto;margin-right:auto;width:400px;}
    #content-end{margin-left:auto;margin-right:auto;width:400px;}

    單行兩列 
    #bodycenter{width:700px;margin-right:auto;margin-left:auto;overflow:auto;}
    #bodycenter#dv1{float:left;width:280px;}
    #bodycenter#dv2{float:right;width:420px;} 

    兩行兩列
    #header{width:700px;margin-right:auto;margin-left:auto;overflow:auto;}
    #bodycenter{width:700px;margin-right:auto;margin-left:auto;overflow:auto;}
    #bodycenter#dv1{float:left;width:280px;}
    #bodycenter#dv2{float:right;width:420px;} 

    三行兩列
    #header{width:700px;margin-right:auto;margin-left:auto;}
    #bodycenter{width:700px;margin-right:auto;margin-left:auto;}
    #bodycenter#dv1{float:left;width:280px;}
    #bodycenter#dv2{float:right;width:420px;}
    #footer{width:700px;margin-right:auto;margin-left:auto;overflow:auto;clear:both;} 

    單行三列

    絕對(duì)定位 
    #left{position:absolute;top:0px;left:0px;width:120px;}
    #middle{margin:0px190px0px190px;}
    #right{position:absolute;top:0px;right:0px;width:120px;} 

    float定位
    xhtml:
    <div id="wrap">
    <div id="column">
    <div id="column1">這里是第一列</div>
    <div id="column2">這里是第二列</div>
    <div class="clear"></div>/*用法web標(biāo)準(zhǔn)不建議,但是記住下面元素需要清除浮動(dòng)*/
    </div>
    <divid="column3">這里是第三列</div>
    <divclass="clear"></div>/*用法web標(biāo)準(zhǔn)不建議,但是記住下面元素需要清除浮動(dòng)*/
    </div> 
    CSS:
    #wrap{width:100;height:auto;}
    #column{float:left;width:60;}
    #column1{float:left;width:30;}
    #column2{float:right;width:30;}
    #column3{float:right;width:40;}
    .clear{clear:both;} 

    float定位二
    xhtml
    <div id="center"class="column">
    <h1>Thisisthemaincontent.</h1>
    </div>
    <div id="left"class="column">
    <h2>Thisistheleftsidebar.</h2>
    </div>
    <div id="right"class="column">
    <h2>Thisistherightsidebar.</h2>
    </div>
    CSS
    body{
    margin:0;
    padding-left:200px;/*LCfullwidth*/
    padding-right:190px;/*RCfullwidth CCpadding*/
    min-width:200px;/*LCfullwidth CCpadding*/
    }
    .column{
    position:relative;
    float:left;
    }
    #center{
    width:100;
    }
    #left{
    width:200px;/*LCwidth*/
    right:200px;/*LCfullwidth*/
    margin-left:-100;
    }
    #right{
    width:190px;/*RCwidth*/
    margin-right:-100;
    }

    /***IEFix***/
    *html#left{
    left:190px;/*RCfullwidth*/
    }

    兩行三列 
    xhtml:

    <div id="header">這里是頂行</div>
    <div id="warp">
    <div id="column">
    <div id="column1">這里是第一列</div>
    <div id="column2">這里是第二列</div>
    <div class="clear"></div>
    </div>
    <div id="column3">這里是第三列</div>
    <div class="clear"></div>
    </div> 
    CSS:
    #header{width:100;height:auto;}
    #wrap{width:100;height:auto;}
    #column{float:left;width:60;}
    #column1{float:left;width:30;}
    #column2{float:right;width:30;}
    #column3{float:right;width:40;}
    .clear{clear:both;} 

    三行三列 
    xhtml:
    <div id="header">這里是頂行</div>
    <div id="wrap">
    <div id="column">
    <div id="column1">這里是第一列</div>
    <div id="column2">這里是第二列</div>
    <div class="clear"></div>
    </div>
    <div id="column3">這里是第三列</div>
    <div class="clear"></div>
    </div>
    <div id="footer">這里是底部一行</div>
    CSS:
    #header{width:100;height:auto;}
    #wrap{width:100;height:auto;}
    #column{float:left;width:60;}
    #column1{float:left;width:30;}
    #column2{float:right;width:30;}
    #column3{float:right;width:40;}
    .clear{clear:both;}
    #footer{width:100;height:auto;} 

    PS:這里列出的是常用的例子,而非研究之用,對(duì)一每個(gè)盒子,我都沒(méi)有設(shè)置margin,padding,boeder等屬性,是因?yàn)槲覀€(gè)人覺(jué)得,含有寬度定位的時(shí)候,最好不好用到他們,除非必不得已,因?yàn)槿绻皇沁@樣的話,解決瀏覽器兼容問(wèn)題,會(huì)讓你頭疼,而且產(chǎn)生一系列CSS代碼,我覺(jué)得這樣的效率和效果都不好! 

    CSS布局高級(jí)技巧
    margin和padding總是有可能要用到,而產(chǎn)生的問(wèn)題如何解決呢?由于瀏覽器解釋容器寬度的方法不同:
    IE6.0FirefoxOpera等是
    真實(shí)寬度=width padding border margin
    IE5.X
    真實(shí)寬度=width-padding-border-margin 

    IE中有浮動(dòng)對(duì)象的雙倍距離之BUG(IEDoubledFloat-MarginBug),這里還需要具體問(wèn)題具體解決,下面是解決辦法www.forest53.com/tutorials/tutorials_show.asp?id=31

    很明顯,第一種下很完美的布局在第二種情況下后果是很凄慘的! 
    解決的方法是hack 
    div.content{
    width:400px;//這個(gè)是錯(cuò)誤的width,所有瀏覽器都讀到了
    voice-family:"\"}\"";//IE5.X/win忽略了"\"}\""后的內(nèi)容
    voice-family:inherit;
    width:300px;//包括IE6/win在內(nèi)的部分瀏覽器讀到這句,新的數(shù)值(300px)覆蓋掉了舊的
    }
    html>body.content{//html>body是CSS2的寫(xiě)法
    width:300px;//支持CSS2該寫(xiě)法的瀏覽器(非IE5)有幸讀到了這一句
    }

    div.content{
    width:300px!important;//這個(gè)是正確的width,大部分支持!important標(biāo)記的瀏覽器使用這里的數(shù)值
    width(空格)/**/:400px;//IE6/win不解析這句,所以IE6/win仍然認(rèn)為width的值是300px;而IE5.X/win讀到這句,新的數(shù)值(400px)覆蓋掉了舊的,因?yàn)?important標(biāo)記對(duì)他們不起作用
    }
    html>body.content{//html>body是CSS2的寫(xiě)法
    width:300px;//支持CSS2該寫(xiě)法的瀏覽器有幸讀到了這一句


    列等高技巧
    n行n列布局,每列高度(事先并不能確定哪列的高度)的相同,是每個(gè)設(shè)計(jì)師追求的目標(biāo),做法有:背景圖填充、加JS腳本的
    方法和容器溢出部分隱藏和列的負(fù)底邊界和正的內(nèi)補(bǔ)丁相結(jié)合的方法。

    背景圖填充法:
    xhtml:
    <div id="wrap">
    <div id="column1">這是第一列</div>
    <div id="column1">這是第二列</div>
    <div class="clear"></div>
    </div>
    css:
    #wrap{width:776px;background:url(bg.gif)repeat-y300px;}
    #column1{float:left;width:300px;}
    #column2{float:right;width:476px;}
    .clear{clear:both;} 

    就是將一個(gè)npx寬的一張圖片在外部容器縱向重復(fù),定位到兩列交錯(cuò)的位置縱向重復(fù),在視覺(jué)上產(chǎn)生了兩列高度一樣的錯(cuò)覺(jué)。
    posted on 2010-02-27 13:01 hankchen 閱讀(2858) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): HTML+CSS

    只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 国产精品偷伦视频免费观看了| 国产一精品一aⅴ一免费| 丁香六月婷婷精品免费观看| 亚洲一区在线视频观看| 亚洲国产精品va在线播放| 国产一级淫片视频免费看| av免费不卡国产观看| 久久久久久久99精品免费观看| 黄页网站在线免费观看| 亚洲色成人网站WWW永久四虎| 久久亚洲私人国产精品| 亚洲人成人77777网站| 又粗又大又硬又爽的免费视频 | 国产免费131美女视频| 无码人妻一区二区三区免费| 99热在线免费播放| 波多野结衣免费一区视频 | 国产一区二区三区无码免费| 国产无人区码卡二卡三卡免费| 一级毛片在线观看免费| 99精品全国免费观看视频..| 特级毛片aaaa免费观看| 极品美女一级毛片免费| 猫咪免费人成在线网站| 男女交性无遮挡免费视频| 免费观看四虎精品成人| 美女视频黄频a免费| 麻豆69堂免费视频| 午夜不卡AV免费| aa在线免费观看| 两个人看的www高清免费视频| 精品国产呦系列在线观看免费| 丁香六月婷婷精品免费观看| 一个人看的hd免费视频| 国产大片免费天天看| yellow免费网站| av永久免费网站在线观看| 香港a毛片免费观看 | 亚洲精品国产成人99久久| 91精品国产亚洲爽啪在线影院| 亚洲永久中文字幕在线|