【css】头部定高,底部占满以及相反操作

 

一、头部定高,底部占满

<html>
<head>
<style type="text/css">
.wrap{
    height:100%;
    position:relative;
}

.wrap>.mytop{
    top:0px;
    left:0px;
    height:40px;
    width:100%;
    background:blue;
    position:absolute;

}

.wrap>.mybottom{
    top:40px;
    left:0px;
    bottom:0px;
    width:100%;
    background:red;
    position:absolute;
}

</style>
</head>

<body>
<div class="wrap">

    <div class="mytop">

    </div>

    <div class="mybottom">

    </div>
</div>
</body>
</html>

 二、头部占满,底部定高

<html>
<head>
<style type="text/css">
.wrap{
    height:100%;
    position:relative;
}

.wrap>.mytop{
    top:0px;
    left:0px;
    bottom:40px;
    width:100%;
    background:blue;
    position:absolute;

}

.wrap>.mybottom{
    height:40px;
    left:0px;
    bottom:0px;
    width:100%;
    background:red;
    position:absolute;
}

</style>
</head>

<body>
<div class="wrap">

    <div class="mytop">

    </div>

    <div class="mybottom">

    </div>
</div>
</body>
</html>

 当然有一种更简便的方法:

 在容器里给一个padding,top定在padding里,bottom高度100%;

.wrpper{

    height: 100%;

    position: relative;

    box-sizing: border-box;

    padding-top: 0.9rem;

    background: #fafafa;

}

头部:

.top {

    box-sizing: border-box;

    padding: .2rem .3rem;

    height: .9rem;

    position:absolute;

    top: 0px;

    left: 0px;

    width: 100%;

}

底部:

.bottom{

height: 100%;

overflow: hidden;

padding: 0px;

margin: 0px;

}

PS:

还有一种方法,再wrap里放一个main,warp给width和height都是100%;

main也是width和height为100%;

然后main还有一些操作:

(1)main有一个padding;架起header或者bottom;

(2)main给一个相对定位:postion:relative

再加一些others给绝对定位

position:absolute

填充main里padding给出的位置

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值