hgq's docs
主页
ES6-阮一峰 (opens new window)
Vue文档 (opens new window)
Axios文档 (opens new window)
Vue Router (opens new window)
Vuex文档 (opens new window)
面试题-Vue (opens new window)
面试题-JS (opens new window)

guoguoqiqi

漫不经心的向往
主页
ES6-阮一峰 (opens new window)
Vue文档 (opens new window)
Axios文档 (opens new window)
Vue Router (opens new window)
Vuex文档 (opens new window)
面试题-Vue (opens new window)
面试题-JS (opens new window)
  • 怎么解决移动端1px问题
  • 说一说对BFC的理解
  • CSS的盒子模型
  • 说一说对flex布局的认识
  • 网格布局
  • 伪类选择器和伪元素
  • 怎么实现响应式布局
  • css中的选择器有哪些、哪些可以继承
  • 如何做移动端适配
  • 如何清除浮动
  • em、rem区别
  • display none与visibility hidden的区别
  • z-index失效的场景
  • 在页面上隐藏元素的方法有哪些
  • css选择器中first-child与first-of-type的区别
  • 用css绘制三角形及其原理
  • 说一说box-sizing属性
  • 说一说水平垂直居中的布局方法
  • CSS 常见布局方式
  • CSS3的新特性有哪些
  • 圣杯布局和双飞翼布局
    • inline、block、inline-block这三个属性值有什么区别
    • 说一说css的预处理器
    • 如果要做优化,CSS提高性能的方法有哪些
    • CSS3常见动画有哪些
    • 怎样画一条0点5px的线
    • CSS
    guoguoqiqi
    2022-03-01

    圣杯布局和双飞翼布局

    # 作用:

    圣杯布局和双飞翼布局解决的问题是一样的,就是两边顶宽,中间自适应的三栏布局,中间栏要在放在文档流前面以优先渲染。

    # 区别:

    圣杯布局,为了中间div内容不被遮挡,将中间div设置了左右padding-left和padding-right后,将左右两个div用相对布局position: relative并分别配合right和left属性,以便左右两栏div移动后不遮挡中间div。双飞翼布局,为了中间div内容不被遮挡,直接在中间div内部创建子div用于放置内容,在该子div里用margin-left和margin-right为左右两栏div留出位置。

    # 示例代码:

    # 圣杯布局

    <body>
    <div id="hd">header</div>
    <div id="bd">
      <div id="middle">middle</div>
      <div id="left">left</div>
      <div id="right">right</div>
    </div>
    <div id="footer">footer</div>
    </body>
    
    <style>
    #hd{
        height:50px;
        background: #666;
        text-align: center;
    }
    #bd{
        /*左右栏通过添加负的margin放到正确的位置了,此段代码是为了摆正中间栏的位置*/
        padding:0 200px 0 180px;
        height:100px;
    }
    #middle{
        float:left;
        width:100%;/*左栏上去到第一行*/
        height:100px;
        background:blue;
    }
    #left{
        float:left;
        width:180px;
        height:100px;
        margin-left:-100%;
        background:#0c9;
        /*中间栏的位置摆正之后,左栏的位置也相应右移,通过相对定位的left恢复到正确位置*/
        position:relative;
        left:-180px;
    }
    #right{
        float:left;
        width:200px;
        height:100px;
        margin-left:-200px;
        background:#0c9;
        /*中间栏的位置摆正之后,右栏的位置也相应左移,通过相对定位的right恢复到正确位置*/
        position:relative;
        right:-200px;
    }
    #footer{
        height:50px;
        background: #666;
        text-align: center;
    }
    </style>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53

    # 双飞翼布局

    <body>
    <div id="hd">header</div> 
      <div id="middle">
        <div id="inside">middle</div>
      </div>
      <div id="left">left</div>
      <div id="right">right</div>
      <div id="footer">footer</div>
    </body>
    
    <style>
    #hd{
        height:50px;
        background: #666;
        text-align: center;
    }
    #middle{
        float:left;
        width:100%;/*左栏上去到第一行*/     
        height:100px;
        background:blue;
    }
    #left{
        float:left;
        width:180px;
        height:100px;
        margin-left:-100%;
        background:#0c9;
    }
    #right{
        float:left;
        width:200px;
        height:100px;
        margin-left:-200px;
        background:#0c9;
    }
    
    /*给内部div添加margin,把内容放到中间栏,其实整个背景还是100%*/ 
    #inside{
        margin:0 200px 0 180px;
        height:100px;
    }
    #footer{  
       clear:both; /*记得清楚浮动*/  
       height:50px;     
       background: #666;    
       text-align: center; 
    } 
    </style>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49

    # 参考文章链接

    深入理解浮动元素与margin负值用法及三栏布局 (opens new window)

    ← CSS3的新特性有哪些 inline、block、inline-block这三个属性值有什么区别→

    最近更新
    01
    vuex数据持久化怎么做
    05-22
    02
    vue的动态路由怎么配置使用
    05-22
    03
    vue权限控制一般怎么做
    05-22
    更多文章>
    Theme by Vdoing | Copyright © 2022-2022 Guoquoqiqi | MIT License
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式