先放html,后放css
头部
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<title>练习</title>
<link rel="stylesheet" href="src\web.css">
<!-- 切记颜色单词别打错了-->
</head>
<body>
<div class="header w">
<div class="logo">
<img src="96/logo.png">
</div>
<div class="nav">
<ul>
<li>< a href="#">首页</ a> </li>
<li>< a href="#">课程</ a> </li>
<li>< a href="#">职业规划</ a> </li>
</ul>
</div>
<div class="search">
<input type="text" value="输入关键词">
<button></button>
</div>
<div class="user">
<img src="96/num_07.gif">
qq.com
</div>
</div>
</body>
</html>
*{
padding:0;
margin:0;
}
.w{
width:1200px;
margin:auto;
}
body{
background-color:#f3f5f7;
}
li{
list-style:none;
}
.header{
height:68px;
margin:30px auto;
}
.logo{
float:left;
width:164px;
height:68px;
}
.nav{
float:left;
margin-left:60px;
}
a{
text-decoration:none;
}
.nav ul li {
float:left;
margin:0 15px;
}
.nav ul li a{
display:block;
height:42px;
padding:0 10px;
line-height:68px;
font-size:24px;
color:#050505;
}
.nav ul li a:hover{
border-bottom:5px solid #00a4ff;
color:#00a4ff;
}
.search{
width:480px;
height:68px;
background-color:skyblue;
float:left;
margin-left:50px;
}
.search input{
width:385px;
height:66px;
border:1px solid #00a4ff;
border-right:0px;
font-size:18px;
padding-left:15px;
float:left;
}
.search button{
float:left;
width:80px;
height:68px;
background:url(96/login.gif);
border:0;
}
.user {
float:right;
line-height:68px;
margin-right:10px;
font-size:18px;
}
banner
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<title>练习</title>
<link rel="stylesheet" href="src\web.css">
<!-- 切记颜色单词别打错了-->
</head>
<body>
<div class="banner">
<div class="w">
<div class="subnav">
<ul>
<li>< a href="#">前端开发</ a> </li>
<li>< a href="#">前端开发</ a> </li>
<li>< a href="#">前端开发</ a> </li>
<li>< a href="#">前端开发</ a> </li>
<li>< a href="#">前端开发</ a> </li>
<li>< a href="#">前端开发</ a> </li>
<li>< a href="#">前端开发</ a> </li>
<li>< a href="#">前端开发</ a> </li>
</ul>
</div>
</div>
</div>
</body>
</html>
*{
padding:0;
margin:0;
}
.w{
width:1200px;
margin:auto;
}
.banner{
margin-top:400px;
height:421px;
background-color:#1c036c;
}
.banner .w{
height:421px;
background:url(96/logo.png) no-repeat top center;
}
.subnav{
width:190px;
height:421px;
background: rgba( 0,0,0,0.3);
}
.subnav ul li{
height:45px;
line-height:45px;
padding:0 20px;
}
.subnav li a{
font-size:14px;
color:white;
}
li{
list-style:none;
}
精品修饰
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<title>练习</title>
<link rel="stylesheet" href="src\web.css">
<!-- 切记颜色单词别打错了-->
</head>
<body>
<div class="banner">
<div class="w">
<div class="subnav">
<ul>
<li>< a href="#">前端开发</ a> </li>
<li>< a href="#">前端开发</ a> </li>
<li>< a href="#">前端开发</ a> </li>
<li>< a href="#">前端开发</ a> </li>
<li>< a href="#">前端开发</ a> </li>
<li>< a href="#">前端开发</ a> </li>
<li>< a href="#">前端开发</ a> </li>
<li>< a href="#">前端开发</ a> </li>
</ul>
</div>
<div class="course">
<h2>我的课程表</h2>
<div class="bd">
<ul>
<li>
<h4>加油学习</h4>
<p>enenenenen</p>
</li>
<li>
<h4>收到收到</h4>
<p>hahahahah</p>
</li>
<li>
<h4>好的好的</h4>
<p>hehehehehe</p>
</li>
</ul>
< a href="#" class="more">全部课程</ a>
</div>
</div>
</div>
</div>
</body>
</html>
*{
padding:0;
margin:0;
}
a{
text-decoration:none;
}
li{
list-style:none;
}
.w{
width:1200px;
margin:auto;
}
.banner{
margin-top:400px;
height:421px;
background-color:#1c036c;
}
.banner .w{
height:421px;
background:url(96/logo.png) no-repeat top center;
}
.subnav{
width:190px;
height:421px;
background: rgba( 0,0,0,0.3);
float:left;
}
.subnav ul li{
height:45px;
line-height:45px;
padding:0 20px;
}
.subnav li a{
font-size:14px;
color:white;
}
.course{
float:right;
width:230px;
height:300px;
background-color:pink;
margin-top:50px;
}
.course h2{
text-align:center;
}
.bd{
margin-left:20px;
}
.bd ul li{
padding:10px 0;
border-bottom:0px solid #ccc;
}
.bd ul li h4{
font-size:14px;
color:#4e4e4e;
}
.bd ul li p{
font-size:12px;
color:#a5a5a5;
}
.more{
width:190px;
display:block;
height:38px;
border:2px solid #00a4ff;
text-align:center;
line-height:38px;
color:#00a4ff;
font-size:16px;
font-weight:700;
margin-top:40px;
}
定位
知识点
定位
选择器`
静态
{position:static;}
相对定位(自己原来位置)
{position:relative;}
绝对定位(父辈位置)
{position:absolute}
固定定位
{position:fixed;}
粘性定位
{position:sticky;top:10px;}
叠放次序
{z-index:1;}
数值越大越上,无单位,只有定位的盒子才有
案例分析
右侧同左侧
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<title>练习</title>
<link rel="stylesheet" href="src\web.css">
<!-- 切记颜色单词别打错了-->
<style>
a{
text-decoration:none;
color:#fff;
}
.tb-promo{
position:relative;
margin:50px 100px;
}
.tb-promo img{
width:140px;
height:125px;
}
.prev{
position:absolute;
left:0;
top:50%;
margin-top:-13px;
width:18px;
height:26px;
background:rgba(0,0,0,.3);
text-align:center;
line-height:26px;
border-top-right-radius:13px;
border-bottom-right-radius:13px;
}
</style>
</head>
<body>
<div class="tb-promo">
<img src="921/1.jpg">
<a href="#" class="prev"><</a>
</div>
</body>
</html>
优化
重复代码多,用并集选择器
右边设next
一个盒子既有left属性也有right属性,则默认执行left属性
同理先执行上非下
.prev,
.next{
position:absolute;
top:50%;
margin-top:-13px;
width:18px;
height:26px;
background:rgba(0,0,0,.3);
text-align:center;
line-height:26px;
}
轮播点
案例分析
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<title>练习</title>
<link rel="stylesheet" href="src\web.css">
<!-- 切记颜色单词别打错了-->
<style>
*{
padding:0;
margin:0;
}
a{
text-decoration:none;
color:#fff;
}
.tb-promo{
position:relative;
margin:80px 43%;
}
.tb-promo img{
width:140px;
height:125px;
}
.promo-nav{
position:absolute;
bottom:10px;
left:50%;
bottom:15px;
margin-left:-35px;
width:70px;
height:13px;
background:rgba(255,255,255,.3);
border-radius:7px;
}
li{
list-style:none;
}
.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="921/1.jpg">
<ul class="promo-nav">
<li></li>
<li class="selected"></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</body>
</html>
隐藏和溢出
visibility和display
overflow
完全显示
.box{
width:444px;
height:320px;
background-color:pink;
margin:30px auto;
}
.box img{
width:100%;
height:100%
}
视频黑色盒子+播放按钮
.box{
width:444px;
height:320px;
background-color:pink;
margin:30px auto;
position:relative;
}
.box img{
width:100%;
height:100%
}
.mask{
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
background:rgba(0,0,0,.3) url(images/arr.png)no-repeat center;
}
隐藏接上面案例
.box{
width:444px;
height:320px;
background-color:pink;
margin:30px auto;
position:relative;
}
.box img{
width:100%;
height:100%
}
.mask{
display:none;
position:absolute;
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
background:rgba(0,0,0,.3) url(images/arr.png)no-repeat center;
}
.box:hover .mask{
diaplay:block;
}
空白和溢出
vertical-align:middle;
图片转块级元素
display:block;
单行溢出
多行溢出
布局技巧
*{
margin:0;
padding:0;
}
.box a{
display:inline-block;
width:36px;
height:36px;
background-color:#f7f7f7;
border:1px solid #ccc;
text-align:center;
line-height:36px;
text-decoration:none;
color:#333;
font-size:14px;
}
.box .prev,
.box .next {
width:85px;
}
.box .current,
.box .elp{
background-color:#fff;
border:none;
}
.box input {
height:36px;
width:45px;
border:1px solid #ccc;
outline:none;
}
.box button{
width:60px;
height:36px;
background-color:#f7f7f7;
border:1px solid #ccc
}
三角强化
.price {
width:160px;
line-height:24px;
border:1px solid red;
margin:0 auto;
height:24px;
}
.miaosha{
position:relative;
right:0;
top:0;
width:90px;
height:100%;
background-color:red;
text-align:center;
color:#fff;
font-weight:700;
margin-right:8px;
}
.miaosha i{
position:absolute;
width:0;
height:0;
border-color:transparent blue transparent transparent;
border-style:solid;
border-width:24px 10px 0 0;
}
.origin {
font-size:12px;
color:gray;
text-decoration:line-through;
}
<div class="price">
<span class="miaosha">
$1650
<i></i>
</span>
<span class="origin">
$5650
</span>
</div>