浮动布局与定位布局

1 html代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>浮动布局与定位布局</title>
    <link rel="stylesheet" href="css/float.css">
</head>
<body>
<header>
    header
</header>
<aside>
    aside
</aside>
<section>
    section
    <textarea></textarea>
</section>
<footer>
    footer
</footer>
</body>
</html>

2 浮动布局css

@charset "UTF-8";
body{
    width: 960px;
    margin: 0 auto;
}
header{
    height: 120px;
    background-color: olive;

}
aside{
    width: 200px;
    height: 400px;
    background-color: purple;
    /*左浮动*/
    float: left;
}
section{
    width: 760px;
    height: 400px;
    background-color: maroon;
    /*右浮动*/
    float: right;
}
footer{
    height: 120px;
    background-color: gray;
    /*清除浮动*/
    clear: both;
}

aside{
    /*元素总高度长度不变,从而不破坏布局*/
    box-sizing: border-box;
    /*加个padding和border测试*/
    padding: 20px;
    border: 5px black solid;
}
/*ps设置:文本框不允许拖动,免得破坏布局*/
textarea{
    resize: none;
}

3 显示效果

4 定位布局css

@charset "UTF-8";
body{
    width: 960px;
    margin: 0 auto;
    /*相对文档定位:body内,不浮动,占位偏移*/
    position: relative;
}
header{
    height: 120px;
    background-color: olive;
}
aside{
    width: 200px;
    height: 400px;
    background-color: purple;
}
section{
    width: 760px;
    height: 400px;
    background-color: maroon;
    /*绝对文档定位:body外,浮动*/
    position: absolute;
    top: 120px;
    right: 0;
}
footer{
    height: 120px;
    background-color: gray;
}
aside{
    /*元素总高度长度不变,从而不破坏布局*/
    box-sizing: border-box;
    /*加个padding和border测试*/
    padding: 20px;
    border: 5px black solid;
}
/*ps设置:文本框不允许拖动,免得破坏布局*/
textarea{
    resize: none;
}

 

转载于:https://www.cnblogs.com/xutaowang/p/9102912.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值