css自适应布局

左右固定,中自适应布局
利用弹性布局,代码如下

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<style>
	.box{
		display: flex;
	}
	.left {
		width: 200px;
		height: 100px;
		float: left;
		background-color: red;
	}
	.right {
		width: 120px;
		height: 100px;
		float: right;
		background-color: blue;
	}
	.middle {
		flex: 1;
		height: 100px;
		background-color: black;
	}
</style>
<body>
	<div class="box">
		<div class="left"></div>
		<div class="middle"></div>
		<div class="right"></div>
	</div>
</body>
</html>
<script>

</script>

左固右适应布局

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<style>
/*  .wrap {
        }

        .left {
            width: 500px;
            height: 200px;
            background-color: red;
            float: left;
        }

        .right {
            margin-left: 500px;
            height: 200px;
            background-color: blue;
        }
 */

/* 方法2 */
        .wrap{
                height: 200px;
        }
        .left{
        width: 500px;
                height: 200px;
        float:left;

        background:red;

        }
    .right{
        overflow:hidden;
                height: 200px;
        background:blue;
        } 

/* 方法3 */
    /* .wrap {
            display: flex;
        }

        .left {
            width: 200px;
            background-color: red;
        }

        .right {
            flex: 1;
            height: 200px;
            background-color: blue;
        } */
</style>
<body>
    <div class="wrap"> 
            <div class="left"></div> 
            <div class="right"></div> 
    </div> 
</body>
</html>

上下固定,中适应并出现滚动条
采用定位

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<style>
	html,body {
		height: 100%;	
		margin:0;
    	padding:0
	}
 
	.header {
		height:100px;
	    line-height:100px;
	    background:red;
	    width:100%;
	    position:absolute;
	    z-index:5;
	    top:0;
	    text-align:center;
	}
	.footer {
		height:100px;
	    line-height:100px;
	    background:blue;
	    width:100%;
	    position:absolute;
	    z-index:200;
	    bottom:0;
	    text-align:center;
	}
	.middlebody {
	    background-color: orange;
	    width:100%;
	    overflow:auto;
	    top:100px;
	    position:absolute;
	    z-index:10;
	    bottom:100px;
	}
	.middle {
		padding: 20px;
	}
</style>
<body>
	<body>
	
		<div class="header"></div>
		<div class="middlebody">
			<div class="middle">
				<p>dadda</p>
				<p>dadda</p>
				<p>dadda</p>
				<p>dadda</p>
				<p>dadda</p>
				<p>dadda</p>
			</div>
		</div>
		<div class="footer"></div>
	
</body>
</body>
</html>

一些布局知识请参考css布局

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值