基本语法
1.语法结构:
选择器
{
属性:属性值;
属性:属性值;
}
2.控制字体:
设置字号----font-size:12px;
设置颜色----color:英文单词;
设置字体----font-family:“宋体”;
设置粗细----font-weight:bold;
设置行高----line-height:150%,1.5em,20px;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS常见样式</title>
<style>
p
{
font-size: large;
color: red;
font-family: "宋体";
line-height: 300%;
font-weight: bold;
}
</style>
</head>
<body>
<p>这是一个p标签</p>
</body>
</html>
3.样式的特点:
(1)继承性:页面中子元素将会继承父元素的样式
(2)层叠性:子元素与父元素同时存在,子元素会覆盖掉父元素的样式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>样式的特点</title>
<style>
body
{
color: red;
}
</style>
</head>
<body>
<p>这是一个段落</p>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>样式的特点</title>
<style>
body
{
color: red;
}
p
{
color: blue;
}
</style>
</head>
<body>
<p>这是一个段落</p>
</body>
</html>
4.控制文本
text-align----文本对齐方式:left,right,center
标签 | 含义 |
---|---|
text-indent | 设置文本的缩进:2em(可以取负数) |
text-align | 文本对齐方式:left,right,center |
text-transform | 文本的大小写 |
text-decoration | 超链接下划线 |
list-style | 无序列表前方序号形状 |
5.案例:导航栏样式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>导航栏</title>
<style>
*
{
margin: 0;/*外对其*/
padding: 0;/*内对其*/
}
.nav/*盒子标签*/
{
border: 1px solod black;
width: 1080px;
height: 60px;
background-image: url(../img/bg.jpg); /*background-color: black;*/
}
li
{
/* border: 1px solid black; */
width: 120px;
height: 60px;
float: left;
list-style: none;
text-indent: 2em;
}
a/*注意就近原则!有些需要写在"a"标签里,有些需要写在"li"里*/
{
color: white;
font-size: 18px;
font-family: "宋体";
line-height: 60px;
text-decoration: double;
/* text-indent: 2em; */
}
li:hover
{
background-color: red;
}
</style>
</head>
<body>
<div class="nav">
<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>
<li><a href="#">游戏九</a></li>
</ul>
</div>
</body>
</html>
6.案例:商品展示
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>商品展示</title>
<style>
*
{
margin: 0;
padding: 0;
}
.container
{
/* border: 1px solid black; */
width: 1200px;
height: 2000px;
margin: 0 auto;
}
.goods
{
border: 1px solid white;
width: 250px;
height: 400px;
float: left;
margin: 10px;
}
.goods:hover
{
border: 1px solid red;
}
</style>
</head>
<body>
<div class="container">
<div class="goods">
<img src="./哆啦A梦 (1).jpg" width="250px" height="300px">
<div style="/*border: 1px solid black;*/ height: 30px;">
<span style="color: red; font-size: 17px; font-weight: bold; line-height: 5px; margin-left: 5px;">$70</span>
<span style="color: #999999; float: right; margin-right: 5px;">2000人付款</span>
</div>
<p><a href="#" style="color: #999999; text-decoration: none; font-size: 13px; margin-left: 5px; font-weight: bold;">哆啦A梦玩偶,重庆直邮</a></p>
<div style="/*border: 1px solid black;*/ height: 30px; line-height: 40px;">
<span style="margin-left: 5px; color: #999999; font-weight: bold;">XXX玩偶官方旗舰店</span>
<span style="color: #999999; float: right; margin-right: 5px;">重庆 巴南</span>
</div>
</div>
<div class="goods">
<img src="./哆啦A梦 (1).jpg" width="250px" height="300px">
<div style="/*border: 1px solid black;*/ height: 30px;">
<span style="color: red; font-size: 17px; font-weight: bold; line-height: 5px; margin-left: 5px;">$70</span>
<span style="color: #999999; float: right; margin-right: 5px;">2000人付款</span>
</div>
<p><a href="#" style="color: #999999; text-decoration: none; font-size: 13px; margin-left: 5px; font-weight: bold;">哆啦A梦玩偶,重庆直邮</a></p>
<div style="/*border: 1px solid black;*/ height: 30px; line-height: 40px;">
<span style="margin-left: 5px; color: #999999; font-weight: bold;">XXX玩偶官方旗舰店</span>
<span style="color: #999999; float: right; margin-right: 5px;">重庆 巴南</span>
</div>
</div>
<div class="goods">
<img src="./哆啦A梦 (1).jpg" width="250px" height="300px">
<div style="/*border: 1px solid black;*/ height: 30px;">
<span style="color: red; font-size: 17px; font-weight: bold; line-height: 5px; margin-left: 5px;">$70</span>
<span style="color: #999999; float: right; margin-right: 5px;">2000人付款</span>
</div>
<p><a href="#" style="color: #999999; text-decoration: none; font-size: 13px; margin-left: 5px; font-weight: bold;">哆啦A梦玩偶,重庆直邮</a></p>
<div style="/*border: 1px solid black;*/ height: 30px; line-height: 40px;">
<span style="margin-left: 5px; color: #999999; font-weight: bold;">XXX玩偶官方旗舰店</span>
<span style="color: #999999; float: right; margin-right: 5px;">重庆 巴南</span>
</div>
</div>
<div class="goods">
<img src="./哆啦A梦 (1).jpg" width="250px" height="300px">
<div style="/*border: 1px solid black;*/ height: 30px;">
<span style="color: red; font-size: 17px; font-weight: bold; line-height: 5px; margin-left: 5px;">$70</span>
<span style="color: #999999; float: right; margin-right: 5px;">2000人付款</span>
</div>
<p><a href="#" style="color: #999999; text-decoration: none; font-size: 13px; margin-left: 5px; font-weight: bold;">哆啦A梦玩偶,重庆直邮</a></p>
<div style="/*border: 1px solid black;*/ height: 30px; line-height: 40px;">
<span style="margin-left: 5px; color: #999999; font-weight: bold;">XXX玩偶官方旗舰店</span>
<span style="color: #999999; float: right; margin-right: 5px;">重庆 巴南</span>
</div>
</div>
<div class="goods">
<img src="./哆啦A梦 (1).jpg" width="250px" height="300px">
<div style="/*border: 1px solid black;*/ height: 30px;">
<span style="color: red; font-size: 17px; font-weight: bold; line-height: 5px; margin-left: 5px;">$70</span>
<span style="color: #999999; float: right; margin-right: 5px;">2000人付款</span>
</div>
<p><a href="#" style="color: #999999; text-decoration: none; font-size: 13px; margin-left: 5px; font-weight: bold;">哆啦A梦玩偶,重庆直邮</a></p>
<div style="/*border: 1px solid black;*/ height: 30px; line-height: 40px;">
<span style="margin-left: 5px; color: #999999; font-weight: bold;">XXX玩偶官方旗舰店</span>
<span style="color: #999999; float: right; margin-right: 5px;">重庆 巴南</span>
</div>
</div>
<div class="goods">
<img src="./哆啦A梦 (1).jpg" width="250px" height="300px">
<div style="/*border: 1px solid black;*/ height: 30px;">
<span style="color: red; font-size: 17px; font-weight: bold; line-height: 5px; margin-left: 5px;">$70</span>
<span style="color: #999999; float: right; margin-right: 5px;">2000人付款</span>
</div>
<p><a href="#" style="color: #999999; text-decoration: none; font-size: 13px; margin-left: 5px; font-weight: bold;">哆啦A梦玩偶,重庆直邮</a></p>
<div style="/*border: 1px solid black;*/ height: 30px; line-height: 40px;">
<span style="margin-left: 5px; color: #999999; font-weight: bold;">XXX玩偶官方旗舰店</span>
<span style="color: #999999; float: right; margin-right: 5px;">重庆 巴南</span>
</div>
</div>
<div class="goods">
<img src="./哆啦A梦 (1).jpg" width="250px" height="300px">
<div style="/*border: 1px solid black;*/ height: 30px;">
<span style="color: red; font-size: 17px; font-weight: bold; line-height: 5px; margin-left: 5px;">$70</span>
<span style="color: #999999; float: right; margin-right: 5px;">2000人付款</span>
</div>
<p><a href="#" style="color: #999999; text-decoration: none; font-size: 13px; margin-left: 5px; font-weight: bold;">哆啦A梦玩偶,重庆直邮</a></p>
<div style="/*border: 1px solid black;*/ height: 30px; line-height: 40px;">
<span style="margin-left: 5px; color: #999999; font-weight: bold;">XXX玩偶官方旗舰店</span>
<span style="color: #999999; float: right; margin-right: 5px;">重庆 巴南</span>
</div>
</div>
<div class="goods">
<img src="./哆啦A梦 (1).jpg" width="250px" height="300px">
<div style="/*border: 1px solid black;*/ height: 30px;">
<span style="color: red; font-size: 17px; font-weight: bold; line-height: 5px; margin-left: 5px;">$70</span>
<span style="color: #999999; float: right; margin-right: 5px;">2000人付款</span>
</div>
<p><a href="#" style="color: #999999; text-decoration: none; font-size: 13px; margin-left: 5px; font-weight: bold;">哆啦A梦玩偶,重庆直邮</a></p>
<div style="/*border: 1px solid black;*/ height: 30px; line-height: 40px;">
<span style="margin-left: 5px; color: #999999; font-weight: bold;">XXX玩偶官方旗舰店</span>
<span style="color: #999999; float: right; margin-right: 5px;">重庆 巴南</span>
</div>
</div>
</div>
</body>
</html>
(其中有许多标签是笔记里没有写的,需要读者有一定的自学能力去"W3school"网站自行搜索学习,另外,因时间仓促和作者水平有限等原因,导致代码编写复杂不便观看,请读者见谅。)