zoukankan      html  css  js  c++  java
  • 常见div+css网页布局(float,absolute)

    网页布局-常见

    1,           float布局

    (1)常规方法

    <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:
    以下是引用片段:
    #wrap{ 100%; height:auto;}
    #column{ float:left; 60%;}
    #column1{ float:left; 30%;}
    #column2{ float:right; 30%;}
    #column3{ float:right; 40%;}
    .clear{ clear:both;}

    (2)margin等于-100%布局

    有margin-left:-100%和margin-right:-100%两种情况,淘宝都有用。

    使用margin-left的有:screen-hd .head 里面包括logo、搜索框和二维码。

    使用margin-right的有:screen-hd .cont 里面包括导航菜单右侧的部分。

    <div id="center" class="column">
        <h1>This is the main content.</h1>
    </div>
    <div id="left" class="column">
        <h2>This is the left sidebar.</h2>
    </div>
    <div id="right" class="column">
        <h2>This is the right sidebar.</h2>
    </div>

    CSS:
    以下是引用片段:
    body {margin: 0;padding-left: 200px;padding-right: 190px;min- 240px;}
    .column {position: relative;float: left;}
    #center { 100%;}
    #left { 180px; right: 240px;margin-left: -100%;}
    #right { 130px;margin-right: -100%;}

    我自己实现的例子:

    <div class="wrap">

           <div class="l">lllllll</div>

           <div class="c"><div class="c-wrap">cccccccccccccccccc</div></div>

           <div class="r">r</div>

    </div>

    .wrap{ 600px; height: 300px; background: #eee;}

    .l{display:inline;float:left; 180px; background:red; margin-right:-100%;}

    .c{display:inline; float:left; 100%; overflow:hidden;}

    .c .c-wrap{margin: 0 180px 0 180px; background:blue; }

    .r{display:inline;float:left;180px; background:yellow; margin-left:-180px;}

    2,           position布局

    #left { position:absolute; top:0px; left:0px; 120px; }
    #middle {margin:20px 190px 20px 190px; }
    #right {position:absolute; top:0px; right:0px; 120px;}

  • 相关阅读:
    POJ 3630 Phone List | Trie 树
    POJ 3974 Palindrome | 马拉车模板
    POJ 3422 Kaka's Matrix Travels | 最小费用最大流
    POJ 2195 Going Home | 带权二分图匹配
    POJ 3068 "Shortest" pair of paths | 最小费用最大流
    POJ 3686 The Windy's | 最小费用最大流
    洛谷 最小费用最大流 模板 P3381
    POJ 2987 Firing | 最大权闭合团
    POJ 3469 Dual Core CPU | 最小割
    POJ 3281 Dining | 最大流
  • 原文地址:https://www.cnblogs.com/zccst/p/3620655.html
Copyright © 2011-2022 走看看