float,posion,浮动和清缓存的方法

less 

*{
margin:0;
padding: 0;
border:0;
}

ul,li{
list-style: none;
}

div{
width:1000px;
margin:0 auto;
overflow: hidden;
>a{
float:left;
width:200px;
height:50px;
line-height: 50px;
background: red;
}
>span{
float:right;
width:200px;
height:50px;
line-height: 50px;
background: orangered;
}
}
section{
width:1000px;
margin:0 auto;
position: relative;
margin-top:100px;
//
&:after{
content: ".";
height: 0;
clear: both;
display: block;
visibility: hidden;
}
>a{
position:absolute;
left:0;
top:0;
width:200px;
height:50px;
line-height: 50px;
background: red;
}
>span{
position: absolute;
right:0 ;
top:0;
width:200px;
height:50px;
line-height: 50px;
background: orangered;
}
}
//行内元素,一旦设置float,position,就会变成块级了,
//。就不用在写display:inline-block;
//float: 用这个overflow
//position: overflow。清除不了元素,添加伪类:
//after{
// content: "";
// height:0;
// display: block;
// clear: both;
//}
//以 position: relative;为基点。设置position: absolute,可堆叠;
//用z-index 调整顺序的显示;并且只对同级标签有用。

清除缓存的方法:

给父容器添加 clearfix 的 class ,用 伪元素 clearfix:after 来设置样式,清除浮动

给父容器添加 overflow:hidden 或者 auto 样式;

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>案例练习</title>
<link rel="stylesheet" href="css/index.css" />
</head>
<body>
<div>
<a href="">asdfasdf</a>
<span>dsfdg</span>
<p>dfsljgslfd</p>
</div>
<section>
<a href="">afsdf</a>
<span>dskafjasl</span>
<p>dajfsljfals</p>
</section>

</body>
</html>

转载于:https://www.cnblogs.com/fengyuzhen34/p/9293260.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值