zoukankan      html  css  js  c++  java
  • CSS---左右固定,中间自适应布局

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8" />
            <title>宽度自适应布局</title>
            <style>
                .wrap {
                    background-color: #D66464;
                }
                .clearfix:after {
                    content: "";
                    clear: both;
                    display: block;
                }
                .left {
                    float: left;
                     100px;
                    background: #00f;
                    height: 180px;
                }
                .right {
                    float: right;
                     150px;
                    background: #0f0;
                    height: 200px;
                }
                .center {
                    background: #FFFFFF;
                    margin-left: 110px;
                    margin-right: 160px;
                    height: 150px;
                }
            </style>
        </head>
        <body>
            <div class="wrap clearfix">
                <div class="left">left,宽度固定,高度可固定也可以由内容撑开。</div>
                <div class="right">right,宽度固定,高度可固定也可以由内容撑开。</div>
                <div class="center">center,可以自适应浏览器宽度,高度可固定也可以由内容撑开。</div>
            </div>
        </body>
    </html>
    
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8" />
            <title>宽度自适应布局</title>
            <style>
                .wrap {
                    background-color: #FBD570;
                    margin-left: 100px;
                    margin-right: 150px;
                }
                .clearfix:after {
                    content: "";
                    clear: both;
                    display: block;
                }
                .left {
                    float: left;
                     100px;
                    background: #00f;
                    height: 180px;
                    margin-left: -webkit-calc(-100% - 100px);
                    margin-left: -moz-calc(-100% - 100px); 
                    margin-left: calc(-100% - 100px); //减号两边必须有空格         
                }
                .right {
                    float: right;
                     150px;
                    background: #0f0;
                    height: 200px;
                    margin-right: -150px;
                }
                .center {
                    background: #B373DA;
                    height: 150px;
                    float: left;
                     100%;
                }
            </style>
        </head>
        <body>
            <div class="wrap clearfix">
                <div class="center">center,可以自适应浏览器宽度,高度可固定也可以由内容撑开。</div>
                <div class="left">left,宽度固定,高度可固定也可以由内容撑开</div>
                <div class="right">right,宽度固定,高度可固定也可以由内容撑开</div>
            </div>
        </body>
    </html>
    
  • 相关阅读:
    js---查找数组中的最大值(最小值),及相应的下标
    JS数组遍历的几种方法
    在 forEach 中使用 async/await 遇到的问题
    js 事件冒泡和事件捕获
    JS中dom0级事件和dom2级事件的区别介绍
    Vue集成Ueditor
    vue富文本编辑器 Vue-Quill-Editor
    Redis问题1---redis满了怎么办
    jQuery火箭图标返回顶部代码
    遇到的小问题
  • 原文地址:https://www.cnblogs.com/beast-king/p/5424742.html
Copyright © 2011-2022 走看看