margin负值基本应用
1.同级标签应用下margin负值
对同级标签应用下margin负值时,会出现标签重叠的效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
div{
width: 120px;
height: 45px;
background-color: #ccc;
border-radius: 15px;
float: left;
line-height: 45px;
text-align: center;
color: #000000;
border: 1px solid blue;
}
.two,.three,.four{
margin-left: -15px;
}
</style>
</head>
<body>
<div class="one">首页</div>
<div class="two">联系我们</div>
<div class="three">公司简介</div>
<div class="four">更多</div>
</body>
</html>
2.对子标签应用margin负值
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
.one{
width: 400px;
height: 50px;
background-color: red;
margin: 100px auto;
border-radius: 6px;
border: 1px solid red;
}
.two{
width: 50px;
height: 50px;
background-color: blue;
margin-left: 30px;
margin-top: -20px;
}
</style>
</head>
<body>
<div class="one">
<div class="two">
</div>
</div>
</body>
</html>
3.利用margin负值制作压线效果
还要实现鼠标悬停时盒子的效果,因此要提高盒子的层级