课堂案例之淘宝焦点图布局
1 页面布局整体思路
2 html+css代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>淘宝轮播图</title>
<style>
* {
margin: 0;
padding: 0;
}
li {
list-style: none;
}
.tb-promo {
/* 子绝父相 */
/* 相对定位 */
position: relative;
width: 520px;
height: 280px;
/* 相对定位可使用margin水平居中,绝对定位和固定定位得使用算法水平居中 */
margin: 100px auto;
}
.tb-promo img {
width: 520px;
height: 280px;
}
/* 由于左按钮和右按钮相同属性及相同属性值很多,故可以使用并集选择器,可以集体声明相同的样式。 */
.prev,
.next {
position: absolute;
top: 50%;
margin-top: -15px;
width: 20px;
height: 30px;
background-color: rgba(0, 0, 0, .3);
text-align: center;
line-height: 30px;
color: #fff;
text-decoration: none;
}
.prev {
/* 绝对定位 */
/* position: absolute; */
left: 0;
/* 垂直居中 */
/* top: 50%;
margin-top: -15px; */
/* 加了绝对定位的盒子可以直接设置高度和宽度 */
/* width: 20px;
height: 30px; */
/* background-color: rgba(0, 0, 0, .3); */
/* 文本水平居中 */
/* text-align: center; */
/* 行高等于高度,使垂直居中 */
/* line-height: 30px; */
/* color: #fff; */
/* 取消下划线 */
/* text-decoration: none; */
/* 使边框右上和右下变为圆角 */
border-top-right-radius: 15px;
border-bottom-right-radius: 15px;
}
.next {
/* 绝对定位 */
/* position: absolute; */
right: 0;
/* top: 50%;
margin-top: -15px; */
/* width: 20px;
height: 30px; */
/* background-color: rgba(0, 0, 0, .3); */
/* text-align: center; */
/* line-height: 30px; */
/* color: #fff; */
/* text-decoration: none; */
border-top-left-radius: 15px;
border-bottom-left-radius: 15px;
}
.promo-nav {
/* 绝对定位 */
position: absolute;
bottom: 15px;
/* 水平居中 */
left: 50%;
margin-left: -35px;
width: 70px;
height: 13px;
background-color: rgba(255, 255, 255, .3);
border-radius: 7px;
}
.promo-nav li {
float: left;
width: 8px;
height: 8px;
background-color: #fff;
border-radius: 50%;
margin: 3px;
}
/* 不要忘记选择器权重问题 */
.promo-nav .selected {
background-color: #ff5000;
}
</style>
</head>
<body>
<div class="tb-promo">
<img src="images/tb.jpg" alt="">
<!-- 左侧按钮箭头 -->
<a href="#" class="prev"> < </a>
<!-- 右侧按钮箭头 -->
<a href="#" class="next"> > </a>
<!-- 小圆点 -->
<ul class="promo-nav">
<li class="selected"></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</body>
</html>