当鼠标悬停在“border-box”区域,显示元素的背景图片被剪裁到边框盒 鼠标设置显示元素没效果
来源:2-4 编程练习
纵有疾风起呵
2019-04-25 22:40:04
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>background-clip</title>
<style type="text/css">
.border,.padding,.content{/*给最外层的div设置样式*/
width:300px;height:300px;
float:left;margin-left:50px;
}
a{
text-decoration:none;
font-size:30px;
}
.div1,.div2,.div3{/*放置背景图片的div样式*/
width:220px;height:200px;
border:10px solid rgba(0,255,0,0.3);
padding:50px;
background-image:url("http://climg.mukewang.com/582c316e0001fd6507000210.jpg");
margin-top:50px;
}
.border:hover div,.padding:hover div,.content:hover div{
display:block;
}
}
.div1{
background-clip: border-box;
}
.div2{
background-clip: padding-box;
}
.div3{
background-clip: content-box;
}
</style>
</head>
<body>
<div class="border">
<a href="">border-box</a>
<div class="div1"></div>
</div>
<div class="padding">
<a href="">padding-box</a>
<div class="div2"></div>
</div>
<div class="content">
<a href="">content-box</a>
<div class="div3"></div>
</div>
</body>
</html>
1回答
好帮手慕慕子
2019-04-26
同学你好, 需要先给背景图片盒子设置display:none属性隐藏,然后鼠标悬停在文字上时显示与之对应的盒子。实现效果
另外, 同学在.div1前多写了一个花括号“}”,虽然不会报错,为了代码书写的规范,建议删除了。
参考下图修改:
如果帮助到了你,欢迎采纳!
祝学习愉快~~
相似问题