案例:
思路:
①得设置4个盒子②盒子可以设置背景图片(backgroundimage)③文字水平垂直居中④鼠标经过换背景图片⑤块内元素转行内块元素
框架:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<a class="one">五彩导航</a>
<a class="two">五彩导航</a>
<a class="three">五彩导航</a>
<a class="four">五彩导航</a>
</div>
</body>
</html>
样式:
.one {
display: inline-block;
background-image: url(imags/bg1.png);
width: 120px;
height: 58px;
text-align: center;
color: white;
line-height: 50px;
}
.two {
display: inline-block;
background-image: url(imags/bg2.png);
width: 120px;
height: 58px;
text-align: center;
color: white;
line-height: 50px;
}
.three {
display: inline-block;
background-image: url(imags/bg3.jpg);
width: 120px;
height: 58px;
text-align: center;
color: white;
line-height: 50px;
}
.four {
display: inline-block;
background-image: url(imags/bg4.png);
width: 120px;
height: 58px;
text-align: center;
color: white;
line-height: 50px;
}
.one:hover {
background-image: url(imags/bg5.png);
}
.two:hover {
background-image: url(imags/bg6.png);
}
.three:hover {
background-image: url(imags/bg7.png);
}
.four:hover {
background-image: url(imags/bg8.png);
}
不熟悉的知识点:
①行和块元素的互相转换(display)
②怎么设置成垂直居中(行高=盒子高度)
③怎么鼠标经过变换背景图片(伪类选择器)
④怎么添加背景:background-image
碎碎念:
第二天案例比较简单继续加油(ง •_•)ง