九宫格
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="./css/font-awesome.min.css">
<link rel="stylesheet" href="./css/icon.css">
</head>
<body>
<style>
body{
background-color: #f4f4f4;
}
ul{
padding: 0;
margin: 0;
list-style: none;
/*box-sizing: border-box;*/
}
ul,li{
box-sizing: border-box;
}
.clearfix::after{
content: "";
display: table;
clear: both;
}
.funcs-container{
width: 290px;
height: 232px;
margin: 100px auto;
/*border: 1px solid red;*/
background-color:#fff;
overflow: hidden;
}
.funcs-container .funcs-list{
width: 294px;
height: 232px;
/*border: 1px solid #000000;*/
margin-left: -2px ;
border-bottom: 1px solid #ddd;
}
.funcs-container .funcs-list .funcs-item{
float: left;
width: 25%;
height: 77px;
border-top: 1px solid #dddddd;
border-left:1px solid #dddddd;
/*border-right: 1px solid #000000;*/
}
.funcs-container .funcs-list .funcs-item .funcs-link{
display: block;
width: 100%;
height: 100%;
}
a{
text-decoration: none;
}
p{
matgin:0;
}
.funcs-container .funcs-list .funcs-item .funcs-link{
font-size: 12px;
color: #333;
text-align: center;
}
</style>
<div class="funcs-container">
<ul class="funcs-list ">
<li class="funcs-item">
<a href="" class="funcs-link">
<i class="icon icon-calendar"></i>
<p>日历</p>
</a>
</li>
<li class="funcs-item">
<a href="" class="funcs-link">
<i class="icon icon-calendar"></i>
<p>日历</p>
</a>
</li>
<li class="funcs-item">
<a href="" class="funcs-link">
<i class="icon icon-calendar"></i>
<p>日历</p>
</a>
</li>
<li class="funcs-item">
<a href="" class="funcs-link">
<i class="icon icon-calendar"></i>
<p>日历</p>
</a>
</li>
<li class="funcs-item">
<a href="" class="funcs-link">
<i class="icon icon-calendar"></i>
<p>日历</p>
</a>
</li>
<li class="funcs-item">
<a href="" class="funcs-link">
<i class="icon icon-calendar"></i>
<p>日历</p>
</a>
</li>
<li class="funcs-item">
<a href="" class="funcs-link">
<i class="icon icon-calendar"></i>
<p>日历</p>
</a>
</li>
<li class="funcs-item">
<a href="" class="funcs-link">
<i class="icon icon-calendar"></i>
<p>日历</p>
</a>
</li>
<li class="funcs-item">
<a href="" class="funcs-link">
<i class="icon icon-calendar"></i>
<p>日历</p>
</a>
</li>
<li class="funcs-item">
<a href="" class="funcs-link">
<i class="icon icon-calendar"></i>
<p>日历</p>
</a>
</li>
<li class="funcs-item">
<a href="" class="funcs-link">
<i class="icon icon-calendar"></i>
<p>日历</p>
</a>
</li>
<li class="funcs-item">
<a href="" class="funcs-link">
<i class="icon icon-calendar"></i>
<p>日历</p>
</a>
</li>
</ul>
</div>
</body>
</html>
/*.icon {*/
/* display: block;*/
/* width: 32px;*/
/* height: 32px;*/
/* background-repeat: no-repeat;*/
/* background-size: 100% 100%;*/
/* margin:10px auto 0;*/
/*}*/
.icon {
display: block;
width: 24px;
height: 24px;
margin: 11px auto 0;
background-repeat: no-repeat;
background-size: 100% 100%;
vertical-align: middle;
/*margin:10px auto 0;*/
}
.icon-calendar {
background-image: url("../icons/calendar.png");
}
/*.icon-goods {*/
/* background-image: url("../icons/goods.png");*/
/*}*/
/*.icon-files {*/
/* background-image: url("../icons/files.png");*/
/*}*/
/*.icon-identity {*/
/* background-image: url("../icons/identity.png");*/
/*}*/
/*.icon-income {*/
/* background-image: url("../icons/income.png");*/
/*}*/
/*.icon-job {*/
/* background-image: url("../icons/job.png");*/
/*}*/
li中因为可以点击跳转所以用a,包裹图标与文字
课程列表
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>腾讯课堂课程列表</title>
<link rel="stylesheet" href="./css/font-awesome.min.css">
<link rel="stylesheet" href="./css/icon.css">
</head>
<body>
<style>
ul{
padding: 0;
margin: 0;
list-style: none;
}
ul,li,div{
box-sizing: border-box;
}
.clearfix::after{
content: '';
display: table;
clear: both;
}
.courses-container{
width: 1230px;
margin: 100px auto;
border: 1px solid red;
}
.courses-container .courses-list{
width: 1500px;
margin-left:-18px ;
/*border: 1px solid orange;*/
}
.courses-container .courses-list .course-item{
float: left;
width: 236px;
height: 221px;
margin-left: 9px;
border: 1px solid #000000;
}
</style>
<div class="courses-container">
<ul class="courses-list clearfix">
<li class="course-item">
</li>
<li class="course-item">
</li>
<li class="course-item">
</li>
<li class="course-item">
</li>
<li class="course-item">
</li>
</ul>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>腾讯课堂课程列表</title>
<link rel="stylesheet" href="./css/font-awesome.min.css">
<link rel="stylesheet" href="./css/icon.css">
</head>
<body>
<style>
ul{
padding: 0;
margin: 0;
list-style: none;
}
ul,li,div{
box-sizing: border-box;
}
i{
font-style: normal;
}
.clearfix::after{
content: '';
display: table;
clear: both;
}
.courses-container{
width: 1230px;
margin: 100px auto;
/*border: 1px solid red;*/
}
.courses-container .courses-list{
width: 1500px;
margin-left:-18px ;
/*border: 1px solid orange;*/
}
.courses-container .courses-list .course-item{
float: left;
position: relative;
width: 236px;
height: 221px;
margin-left: 9px;
/*border: 1px solid #000000;*/
padding: 7px 7px 10px;
/*padding: 7px 20px 10px;*/
border: 1px solid transparent;
}
.courses-container .courses-list .course-item .course-tip{
position: absolute;
left: 7px;
width: 220px;
/*top: 131px;*/
/*top: 100px;*/
/*top: 80px;*/
/*top: 85px;*/
top: 105px;
height: 24px;
}
.courses-container .courses-list .course-item .course-tip2{
position: absolute;
left: 7px;
width: 220px;
/*top: 131px;*/
/*top: 100px;*/
/*top: 80px;*/
/*top: 85px;*/
top: 105px;
height: 24px;
line-height: 24px;
background-color: rgba(0,0,0,.6);
color: #ffffff;
font-size: 12px;
padding: 0 2px;
}
.courses-container .courses-list .course-item .opacity-block{
height: 100%;
background-color: #000000;
opacity: .6;
filter: alpha(opacity=60);
}
.courses-container .courses-list .course-item .course-tip .content-block {
position: absolute;
top: 0;
left: 0;
z-index: 1;
color: #ffffff;
width: 100%;
height: 100%;
line-height: 24px;
font-size: 12px;
padding:0 2px;
}
.courses-container .courses-list .course-item:hover{
/*border: 1px solid #dddddd;*/
border-color: #dddddd;
box-shadow: 0 0 5px #dddddd;
}
.courses-container .courses-list .course-item .course-link{
display: block;
width: 220px;
height: 124px;
margin-bottom: 5px;
/*margin: 0 auto;*/
}
.courses-container .courses-list .course-item .course-link img{
width: 100%;
}
h4{
margin: 0;
font-weight: normal;
}
.courses-container .courses-list .course-item .course-title{
height: 40px;
margin-bottom: 8px;
/*line-height: 40px;*/
font-size: 14px;
color: #333;
}
.courses-container .courses-list .course-item .course-title a{
color: #333;
}
.courses-container .courses-list .course-item .course-title a:hover{
color: #13d0a1;
}
a{
text-decoration: none;
}
.courses-container .courses-list .course-item .course-info{
height: 24px;
line-height: 24px;
}
.courses-container .courses-list .course-item .course-info .info-free{
font-size: 14px;
color: #5fb41b;
}
.courses-container .courses-list .course-item .course-info .info-users{
float: right;
color: #999999;
font-size: 12px;
}
.courses-container .courses-list .course-item .course-info .info-price {
/*font-size: 14px;*/
color: #e85308;
}
.courses-container .courses-list .course-item .course-info .tip-badge{
display: inline-block;
height: 16px;
line-height: 16px;
padding: 0 2px;
border: 1px solid #e85308;
font-size: 12px;
color:#e85308 ;
/*vertical-align: middle;*/
vertical-align: -3px;
vertical-align: 5px;
vertical-align: 2px;
}
</style>
<div class="courses-container">
<ul class="courses-list clearfix">
<li class="course-item">
<div class="course-tip">
<div class="content-block">随到随学(共7节)</div>
<div class="opacity-block"></div>
</div>
<a href="" class="course-link">
<img src="./img/1.png" alt="">
</a>
<h4 class="course-title">
<a href="">【罗翔】4500买的吊坠价值20万?张女士赚了个10年有期徒刑?</a>
</h4>
<div class="course-info">
<span class="info-free">免费</span>
<span class="info-users">2750人 最近报名</span>
</div>
</li>
<li class="course-item">
<div class="course-tip2">
<!-- <div class="content-block">随到随学(共7节)</div>-->
<span class="tip-text">随到随学(共7节)</span>
<!-- <div class="opacity-block"></div>-->
</div>
<a href="" class="course-link">
<img src="./img/1.png" alt="">
</a>
<h4 class="course-title">
<a href="">【罗翔】4500买的吊坠价值20万?张女士赚了个10年有期徒刑?</a>
</h4>
<div class="course-info">
<span class="info-free">免费</span>
<span class="info-users">2750人 最近报名</span>
</div>
</li>
<li class="course-item">
<a href="" class="course-link">
<img src="./img/1.png" alt="">
</a>
<h4 class="course-title">
<a href="">【罗翔】4500买的吊坠价值20万?张女士赚了个10年有期徒刑?</a>
</h4>
<div class="course-info">
<span class="info-free">免费</span>
<span class="info-users">2750人 最近报名</span>
</div>
</li>
<li class="course-item">
<a href="" class="course-link">
<img src="./img/1.png" alt="">
</a>
<h4 class="course-title">
<a href="">【罗翔】4500买的吊坠价值20万?张女士赚了个10年有期徒刑?</a>
</h4>
<div class="course-info">
<span class="info-price">¥999.00</span>
<i class="tip-badge">可试学</i>
<span class="info-users">2750人 最近报名</span>
</div>
</li>
<li class="course-item">
<a href="" class="course-link">
<img src="./img/1.png" alt="">
</a>
<h4 class="course-title">
<a href="">【罗翔】4500买的吊坠价值20万?张女士赚了个10年有期徒刑?</a>
</h4>
<div class="course-info">
<span class="info-free">免费</span>
<span class="info-users">2750人 最近报名</span>
</div>
</li>
<!-- <li class="course-item">-->
<!-- <a href="" class="course-link">-->
<!-- <img src="./img/1.png" alt="">-->
<!-- </a>-->
<!-- <h4>111111</h4>-->
<!-- </li>-->
<!-- <li class="course-item">-->
<!-- </li>-->
<!-- <li class="course-item">-->
<!-- </li>-->
<!-- <li class="course-item">-->
<!-- </li>-->
</ul>
</div>
</body>
</html>
总结
当多个元素在内部,左对齐,左边有边距时可以用padding
其实也可以,再套用一个div,div>div,再拿子div放这些元素,设置padding相当于在div中加了个盒子div,相当于套了个盒子
与文档流不一致时,多用float,因为可以自动排列,按照一定顺序,从左到右,从上到下。从左到右也遵循着流。
决定定位也可以脱离文档流,需要在父级元素精确定位时用