DIV+CSS 三栏布局

1.要求:如上图中的,三栏目布局,中间的MAIN是自适应浏览器的宽度,左LEFT固定宽200PX,右RIGHT固定宽200PX;

.right,.left{height:300px;width:200px;}
.right{ float:right;background:#000000;}
.left{ float:left;background:#009933;}
.main{background:#F60; height:300px;}
     <div class="right">RIGHT</div>
    <div class="left">LEFT</div>
    <div class="main">MAIN</div>    

2.现在要求先加载MIAN,其它要求同上面一样;

总结:主要是利用浮动元素的负外边距;

  并且要理解float和绝对定位,这两种元素的宽度都是根据内容的宽度来的。

  相对定位和块级元素,如果不设定宽,都是100%(相对于父级的宽)

  DEMO下载

.boxmain{float:left;margin-right:-200px;width:100%;}
.right,.left{height:300px;width:200px; z-index:1;}
.right{ position:absolute; right:0; background:#000000;}
.left{position:absolute;left:0; background:#009933;}
.main{margin-right:200px;background:#F60; height:300px;margin-left:200px;}

 

    <div class="boxmain">
        <div class="main">main</div>    
    </div>
    <div class="left">LEFT</div>
    <div class="right">RIGHT</div>

相关文章:

  • 2021-05-17
  • 2022-12-23
  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-02
猜你喜欢
  • 2022-02-06
  • 2021-09-06
  • 2022-02-20
  • 2022-02-13
  • 2022-01-17
相关资源
相似解决方案