zoukankan      html  css  js  c++  java
  • 如何布局左固定右边自适应的两列布局?

    一,左侧div,float设为left,右侧div设置margin-left属性为左侧div的宽度,外div清除浮动

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>Document</title>
     6 </head>
     7 <style type="text/css">
     8     *{margin:0;padding: 0;}
     9     body,html{height: 100%;}
    10     .container{
    11         width: 1000px;
    12         margin:0 auto;
    13         background: #c6c;
    14         overflow: hidden;
    15         height: 100%;
    16     }
    17     .side{
    18         width: 200px;
    19         background: #c66;
    20         height: 100%;
    21         float: left;
    22         /*解决IE6的3px-Bug*/
    23      /*IE6下当浮动元素与非浮动元素相邻时,3px的Bug就会出现,它会偏移3像素。*/
    24       _margin-right: -3px;
    25     }
    26     .main{
    27         background: #6c6;
    28         height: 100%;
    29         margin-left: 200px;
    30   }
    31 </style>
    32 <body>
    33     <div class="container">
    34         <div class="side">side</div>
    35         <div class="main">main</div>
    36     </div>
    37 </body>
    38 </html>

    二,左侧div,float设为left,右侧div设置margin-left属性为左侧div的宽度,外div清除浮动,设置为相对定位,右侧设置绝对定位,宽度100%。(此方法代码比一多了好多代码)

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>Document</title>
     6 </head>
     7 <style type="text/css">
     8     .container{width: 1000px;margin:0 auto;background: #c6c;position: relative;overflow: hidden;}
     9     .side{width: 200px;background: #c66;height: 500px;float: left;}
    10     .main{background: #6c6;height: 500px;margin-left: 200px;position: absolute;top:0;width: 100%;}
    11 </style>
    12 <body>
    13     <div class="container">
    14         <div class="side">side</div>
    15         <div class="main">main</div>
    16     </div>
    17 </body>
    18 </html>

     3.左侧绝对定位

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>Document</title>
     6 </head>
     7 <style type="text/css">
     8     .container{
     9         width: 1000px;
    10         margin:0 auto;
    11         background: #c6c;
    12         position: relative;
    13     }
    14     .side{
    15         width: 200px;
    16         background: #c66;
    17         height: 500px;
    18         position: absolute;
    19         top:0;
    20         left: 0;
    21     }
    22     .main{background: #6c6;height: 500px;margin-left: 200px;}
    23 </style>
    24 <body>
    25     <div class="container">
    26         <div class="side">side</div>
    27         <div class="main">main</div>
    28     </div>
    29 </body>
    30 </html>
  • 相关阅读:
    [leetcode-788-Rotated Digits]
    [leetcode-783-Minimum Distance Between BST Nodes]
    [leetcode-775-Global and Local Inversions]
    [leetcode-779-K-th Symbol in Grammar]
    对于网站,APP开发流程的理解
    进程与线程的一个简单解释【摘】
    快速入手Web幻灯片制作
    Spring MVC Hibernate MySQL Integration(集成) CRUD Example Tutorial【摘】
    linux下SVN服务器配置
    Mac OS X 下android环境搭建
  • 原文地址:https://www.cnblogs.com/MissBean/p/buju.html
Copyright © 2011-2022 走看看