1.外边距合并问题:解决方法
浮动元素,绝对定位(固定)元素都不会触发外边距合并问题2.综合案例-淘宝轮播图
代码:<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
li{
list-style: none;
}
.taobao{
margin:40px auto;
width: 520px;
height: 280px;
background-color: pink;
/*子绝父相*/
position: relative;
}
.arrow-l{
/*float:left;*/
/*只能用定位才能压住盒子*/
/*不要占有位置,随便移动位置,必须用绝对定位*/
position: absolute;
/*绝对定位的盒子无需转换,直接给大小就好了*/
width: 20px;
height: 30px;
background: rgba(0,0,0, .2);
/*垂直居中的公式*/
/*1.走父级高度的50%*/
top:50%;
/*2.往上走 自己高度的一半*/
margin-top:-15px;
left: 0;
/*去掉a的下划线*/
text-decoration: none;
/*圆角矩形*/
/*右上角*/
border-top-right-radius: 15px;
/*右下角*/
border-bottom-right-radius: 15px;
color: white;
line-height: 30px;
text-align:left;
}
.arrow-r{
/*float:left;*/
/*只能用定位才能压住盒子*/
/*不要占有位置,随便移动位置,必须用绝对定位*/
position: absolute;
/*绝对定位的盒子无需转换,直接给大小就好了*/
width: 20px;
height: 30px;
background: rgba(0,0,0, .2);
/*垂直居中的公式*/
/*1.走父级高度的50%*/
top:50%;
/*2.往上走 自己高度的一半*/
margin-top:-15px;
right: 0;
/*去掉a的下划线*/
text-decoration: none;
/*圆角矩形*/
/*右上角*/
/*border-top-left-radius: 15px;*/
/*右下角*/
/*border-bottom-left-radius: 15px;*/
color: white;
border-radius: 15px 0 0 15px;
line-height: 30px;
text-align: right;
}
.arrow-l:hover,
.arrow-r:hover{
background: rgba(0,0,0, .4);
}
.circle{
position:absolute;
bottom: 15px;
/*水平居中*/
left:50%;
margin-left: -35px;
width: 70px;
height: 13px;
background:rgba(255,255,255,0.3);
border-radius: 7px;
}
.circle li{
width: 8px;
height: 8px;
/*background-color: pink;*/
background-color: #fff;
float: left;
border-radius: 50%;
margin: 3px;
}
.circle .current{
background-color: #ff5000;
}
</style>
</head>
<body>
<div class="taobao">
<!-- 左按钮 -->
<a href="#" class="arrow-l"><</a>
<!-- 右按钮 -->
<a href="#" class="arrow-r">></a>
<img src="imgs/taobao.jpg" alt="">
<!-- 小圆点 -->
<ul class="circle">
<li></li>
<li class="current"></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</body>
</html>
运行结果:
2.1知识点补充--圆角矩形
圆角矩形可以分为4个角分别设置圆度,但是是有顺序的boder-top-left-radius:20px;
boder-top-right-radius:20px;
border-bottom-right-radius:20px;
boder-bottom-left-radius:20px;
如果四个角数值相同
boder-radius:15px;
里面数值不同,我们也可以按照简写的形式,具体格式如下
boder-radius:左上角 右上角 右下角 左下角;
3.定位小结
注意:
- 1.边偏移需要和定位模式联合使用,单独使用无效
- top和bottom不要同时使用,left,right同理