• 【面试题】圣杯布局和双飞翼布局


    圣杯布局和双飞翼布局的特点:

    • 三栏布局,中间一栏最先加载和渲染(内容最重要)
    • 两侧内容固定,中间内容随着宽度自适应
    • 一般用于PC页面

    圣杯布局和双飞翼布局的实现方式:

    • 使用float布局
    • 两侧使用margin负值,以便和中间内容横向重叠
    • 为了防止中间内容被两侧覆盖,圣杯布局用padding留出空间,双飞翼布局使用margin

    1. 圣杯布局

    DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>圣杯布局title>
        <style type="text/css">
            body{
                min-width: 550px;
            }
            #header{
                text-align: center;
                background-color: #f1f1f1;
            }
            #center{
                background-color: #ccc;
                width: 100%;
            }
            #left{
                position: relative;
                background-color: yellow;
                width: 200px;
                margin-left: -100%;
                right: 200px;
            }
            #right{
                background-color: red;
                width: 150px;
                margin-right: -150px;
            }
            #footer{
                text-align: center;
                background-color: #f1f1f1;
                clear: both;
            }
    
            #container .column{
                float: left;
            }
    
            #container{
                padding-left: 200px;
                padding-right: 150px;
            }
        style>
    head>
    <body>
        <div id = "header">this is headerdiv>
        <div id = "container">
            <div id = "center" class="column">this is centerdiv>
            <div id = "left" class="column">this is leftdiv>
            <div id = "right" class="column">this is rightdiv>
        div>
        <div id = "footer">this is 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
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57

    效果
    在这里插入图片描述

    2. 双飞翼布局

    DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>双飞翼布局title>
        <style>
            body{
                min-width: 550px;
            }
            .col{
                float: left;
            }
            #main{
                width: 100%;
                height: 200px;
                background-color: #ccc;
            }
            #main-wrap{
                margin: 0 190px 0 190px
            }
            #left{
                width: 190px;
                height: 200px;
                background-color: #0000ff;
                margin-left: -100%;
            }
            #right{
                width: 190px;
                height: 200px;
                background-color: #ff0000;
                margin-left: -190px;
            }
        style>
    head>
    <body>
        <div id="main" class="col">
            <div id = "main-wrap">
                this is main
            div>
        div>
        <div id="left" class="col">
            this is left
        div>
        <div id="right" class="col">
            this is right
        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

    效果
    在这里插入图片描述

    3. 手写clear fix

    clearfix可以用于清除浮动,加在浮动的元素上

    .clearfix:after{
    	content: '';
    	display: table;
    	clear: both;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
  • 相关阅读:
    java计算机毕业设计线上文具销售系统源程序+mysql+系统+lw文档+远程调试
    Spring-kafka配置参数详解,消息批量发送与批量接收消费
    Table-GPT:让大语言模型理解表格数据
    GIF动图怎么变成jpg动图?一键分解GIF动画
    【前端寻宝之路】学习和总结CSS的字体属性设置
    CTO(技术总监)平时都在做些什么?
    Flowable工作流之各种网关
    WebRTC
    Linux aarch64交叉编译之 nodejs js运行时环境
    c语言字符指针、字符串初始化问题
  • 原文地址:https://blog.csdn.net/zx1041561837/article/details/127916097