css如何布局

说一下布局情况:
左右布局(其中左方宽度固定,右方自适应)
右方:上中下布局,中间高度自适应,上下固定

clipboard.png

大家的回家都很有效,谢谢各位。按时间顺序来,采纳第一个。

阅读 2.3k
3 个回答

写一个非flex版的

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <style>
        *{box-sizing: border-box;margin: 0;padding: 0;}
        html,body{height:100%;width:100;}
        .box{
            width: 100%;
            height: 100%;
            border: 1px solid red;
        }
        .left{
            width:200px;
            height:100%;
            background: #f00;
            float: left;
        }
        .right{
            width: calc(100% - 200px);
            height:100%;
            background: #0f0;
            padding: 200px 0;
            position: relative;
            float: right;
        }
        .top,.bottom{
            position: absolute;
            background:#00f;
            height:200px;
            width: 100%;
        }
        .top{top:0;}
        .bottom{bottom:0;}
        .mid{width:100%;height:100%}
    </style>
</head>
<body>
    <div class="box">
        <div class="left"></div>
        <div class="right">
            <div class="top"></div>
            <div class="mid"></div>
            <div class="bottom"></div>
        </div>
    </div>
</body>
</html>

希望对你有所帮助!


直接复制粘贴运行便可看到效果:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            text-align: center;
        }
        html, body {
            width: 100%;
            height: 100%;
        }
        .box {
            position: relative;
            width: 100%;
            height: 100%;
        }
        .left_main {
            float: left;
            width: 300px;
            height: 100%;
            background: red;
        }
        .right_main {
            position: relative;
            float: left;
            width: calc( 100% - 300px );
            height: 100%;
        }
        .right_main .right_top, .right_main .right_bottom{
            position: absolute;
            width: 100%;
            height: 100px;
            left: 0;
        }
        .right_main .right_top {
            top: 0;
            background: orange;
        }
        .right_main .right_bottom {
            bottom: 0;
            background: green;
        }
        .right_main .right_middle {
            position: relative;
            top: 100px;
            width: 100%;
            height: calc( 100% - 100px - 100px );
            background: yellow;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="left_main">左边固定宽度</div>
        <div class="right_main">
            <div class="right_top">上方固定高度</div>
            <div class="right_middle">中间高度自适应</div>
            <div class="right_bottom">下方固定高度</div>
        </div>
    </div>
</body>
</html>

运行效果图

clipboard.png

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题