超级链接a的修饰
html结构:超级链接a
<a href="www.baidu.com" target="_blank"></a>
- a的4个状态
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>a标签的四个状态</title>
</head>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
a:link{
color: khaki;
/*访问之前的状态*/
}
a:visited{
color:red
/*访问之后的状态*/
}
a:hover{
color: salmon;
/*鼠标移动到超链接的颜色*/
}
a:active{
color:green;
/*鼠标按住不动的颜色*/
}
</style>
<body>
<a href="http://wwww.baidu.com" target="_blank">点击跳转到度娘</a>
</body>
</html>
访问顺序l o v e h a t e
2.a标签的实际应用
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>a标签的实际应用</title>
</head>
<style type="text/css">
body{
font-size: 20px;
color: #333;
line-height: 50px;
font-family: "微软雅黑";
font-weight: bold;
text-decoration: none;
}
*{
padding: 0;
margin: 0;
}
a{
display: block;
width: 200px;
height: 50px;
border: 1px solid #000;
background: pink;
color: #333;
text-decoration: none;
text-align: center;
}
a:hover{
background: green;
color: #FFFF00;
}
a:active{
background: skyblue;
color: red;
}
</style>
<body>
<a href="https://www.bilibili.com" target="_blank">点击跳转到度娘</a>
</body>
</html>
效果图
background背景
background是一个复合属性
①background-color 背景色
例子: 简易导航栏
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>简单导航栏</title>
</head>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
ul{
list-style: none;
}
.nav{
width: 960px;
background: #ccc;
margin: 50px auto;
overflow: hidden;
font-size: 14px;
font-family: "微软雅黑";
color: #252525;
line-height: 30px;
text-align: center;
}
.nav ul{
overflow: hidden;
}
.nav ul li{
float: left;
width: 120px;
}
.nav ul li a {
display: block;
width: 120px;
height: 30px;
color: #252525;
text-decoration: none;
}
.nav ul li.current a{
background: skyblue;
color: #fff;
font-weight: bold;
}
.nav ul li a:hover{
background: rgba(135,206,235,0.5);
color: #fff;
font-weight: bold;
}
</style>
<body>
<div class="nav">
<ul>
<li class="current"><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>
效果图
②background-image背景图
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>background-image</title>
</head>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
.box{
width: 400px;
height: 400px;
border: 1px solid #000;
background-image: url(images/123.jpg);
margin: 100px;
}
</style>
<body>
<div class="box">
</div>
</body>
</html>
③.背景重复background-repeat
属性值:
repeat 默认值,整个背景区域重复
no-repeat 不重复
repeat-x 水平方向重复
repeat-y 垂直方向重复
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>背景重复</title>
</head>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
.box{
width: 400px;
height: 400px;
border: 1px solid #000;
background-image: url(images/3.jpg);
background-repeat: repeat-x;
margin: 100px;
}
</style>
<body>
<div class="box">
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>背景重复</title>
</head>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
.box{
width: 400px;
height: 400px;
border: 1px solid #000;
background-image: url(images/3.jpg);
background-repeat: repeat-y;
margin: 100px;
}
</style>
<body>
<div class="box">
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>背景重复</title>
</head>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
.box{
width: 400px;
height: 400px;
border: 1px solid #000;
background-image: url(images/3.jpg);
background-repeat: repeat;
margin: 100px;
}
</style>
<body>
<div class="box">
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>背景重复</title>
</head>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
body{
background-image: url(images/back.jpg);
}
.box{
width: 400px;
height: 400px;
border: 1px solid #000;
background-image: url(images/3.jpg);
background-repeat: repeat;
margin: 100px;
}
</style>
<body>
<div class="box">
</div>
</body>
</html>
④.background-position背景相对位置
属性值:像素表示法、单词表示法、百分比表示法
1.像素表示法:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>背景图相对定位</title>
</head>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
.box{
width: 400px;
height: 400px;
border: 1px solid #000;
margin:100px;
background-image: url(images/wawa.jpg);
background-repeat: no-repeat;
/*两个属性值分别为x,y*/
background-position: 150px 100px;
}
</style>
<body>
<div class="box">
</div>
</body>
</html>
2.单词表示法
图片位置用代表的英文单词表示
水平方向:left center right
垂直方向:top center bottom
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>背景图相对定位</title>
</head>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
.box{
width: 400px;
height: 400px;
border: 1px solid #000;
margin:100px;
background-image: url(images/wawa.jpg);
background-repeat: no-repeat;
/*两个属性值分别为*/
/*background-position: 150px 100px;*/
background-position: left center;
}
</style>
<body>
<div class="box">
</div>
</body>
</html>
3.百分比表示法
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>背景图相对定位</title>
</head>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
.box{
width: 400px;
height: 400px;
border: 1px solid #000;
margin:100px;
background-image: url(images/wawa.jpg);
background-repeat: no-repeat;
/*两个属性值分别为*/
/*background-position: 150px 100px;*/
/*background-position: left center;*/
background-position:0% 50%;
}
</style>
<body>
<div class="box">
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>背景图相对定位</title>
</head>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
.box{
width: 400px;
height: 400px;
border: 1px solid #000;
margin:100px;
background-image: url(images/wawa.jpg);
background-repeat: no-repeat;
/*两个属性值分别为*/
/*background-position: 150px 100px;*/
/*background-position: left center;*/
background-position:100% 50%;
}
</style>
<body>
<div class="box">
</div>
</body>
</html>
⑤background-attachment背景附着
指的是背景图片是否随着页面滚动而滚动
属性值:
scroll 滚动,背景图会随着页面动
fixed 不会滚动
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>背景滚动</title>
</head>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
body{
background-image: url(images/back.jpg);
background-repeat: repeat-x;
background-position: center top;
background-attachment: fixed;
}
div{
width: 100px;
height:100px;
background-color:skyblue ;
margin-bottom: 50px;
}
</style>
<body>
<div><h1>1</h1></div>
<div><h1>2</h1></div>
<div><h1>3</h1></div>
<div><h1>4</h1></div>
<div><h1>5</h1></div>
<div><h1>6</h1></div>
<div><h1>7</h1></div>
<div><h1>8</h1></div>
</body>
</html>
复合写法
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>背景滚动</title>
</head>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
body{
/*background-image: url(images/back.jpg);
background-repeat: repeat-x;
background-position: center top;
background-attachment: fixed;*/
background: url(images/back.jpg) repeat-x center top fixed skyblue;
}
div{
width: 100px;
height:100px;
background-color:skyblue ;
margin-bottom: 50px;
}
</style>
<body>
<div><h1>1</h1></div>
<div><h1>2</h1></div>
<div><h1>3</h1></div>
<div><h1>4</h1></div>
<div><h1>5</h1></div>
<div><h1>6</h1></div>
<div><h1>7</h1></div>
<div><h1>8</h1></div>
</body>
</html>