• CSS经典布局--圣杯布局和双飞翼布局


    圣杯布局与双飞翼布局,都是属于三列布局的经典布局。
    双飞翼布局是圣杯布局的优化版,由淘宝UED提出;
    它们的效果图类似,但是实现方法不同。

    一、圣杯布局和双飞翼布局的常规方法

    首先打好底子(两者共用)

    DOCTYPE html>
    <html>
    
    <head>
      <meta charset="utf-8">
      <title>1111title>
    head>
    <style>
      .header, .footer {
        height: 50px;
        background: lightblue;
      }
    
      .center {
        width: 100%;
        height: 500px;
        background: lightgray;
        float: left;
      }
    
      .left {
        width: 200px;
        height: 500px;
        background: lightpink;
        float: left;
        margin-left: -100%; /* 浮动,w100%,不在同行 */
      }
    
      .right {
        width: 300px;
        height: 500px;
        background: lightgreen;
        float: left;
        margin-left: -300px;
      }
    
      .clearfix::before,
      .clearfix::after {
        content: "";
        display: block;
        clear: both;
      }
    style>
    
    <body>
      <div class="header">头部div>
      <div class="main clearfix">
        
        <div class="center">
          中间自适应
        div>
        <div class="left">左列定宽div>
        <div class="right">右列定宽div>
      div>
      <div class="footer">底部div>
    body>
    
    html>
    
    • 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
    • 54
    • 55
    • 56
    • 57
    • 58

    在这里插入图片描述
    此时 “center” 中间自适应 被遮挡

    1.圣杯 position 解决(不推荐):

    css

      /* 圣杯 */
      .main {
        margin-left: 200px;
        margin-right: 300px;
      }
    
      .left {
        position: relative;
        left: -200px;
      }
    
      .right {
        position: relative;
        right: -300px;
      } 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    在这里插入图片描述
    解决了遮挡,但是当屏幕缩小,布局会乱!!!
    在这里插入图片描述

    2.双飞翼布局:

    html

    // center 加个div 文字放里面 
    <div class="center">
          <div class="inner">中间自适应div>
    div>
    
    • 1
    • 2
    • 3
    • 4

    css

      /* 双飞翼 */
      .inner {
        /* height: 100%; */
        margin:0 300px 0 200px;
        border: 2px solid red;
      }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    在这里插入图片描述

    二、圣杯布局–flex实现(推荐)

    DOCTYPE html>
    <html>
    
    <head>
      <meta charset="utf-8">
      <title>圣杯-flextitle>
    head>
    <style>
      #header,  #footer {
        background: yellowgreen;
        height: 60px;
        line-height: 60px;
      }
    
      #container {
        display: flex;
      }
    
      #container .column {
        height: 300px;
        line-height: 300px;
      }
    
      #center {
        flex-grow: 1;
        background: gray;
      }
    
      #left {
        width: 200px;
        order: -1;
        background: beige;
      }
    
      #right {
        width: 200px;
        background:paleturquoise;
      }
    style>
    
    <body>
      <div id="header">#headerdiv>
      <div id="container">
      	<div id="center" class="column">#centerdiv>
        <div id="left" class="column">#leftdiv>
        <div id="right" class="column">#rightdiv>
      div>
      <div id="footer">#footerdiv>
    body>
    
    html>
    
    • 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

    在这里插入图片描述

  • 相关阅读:
    【SQLite】一、SQLite简介——MySQL的简洁版
    vue3之pinia简单使用
    多测师肖sir_高级讲师_第2个月第12讲pyhton+pymysql
    商场百货数字化会员系统引流方式 购物中心线上会员拉新
    关于ubuntu开发环境配置
    switch语句深讲
    vue3+element-plus之自定义表格
    RML2016调制识别
    IDEA使用http client无法识别http-client.env.json的环境配置
    pySpark,执行算子show(1)导致并行度不对的问题
  • 原文地址:https://blog.csdn.net/W2001r/article/details/125703959