老师这样写,对不对?
来源:2-4 编程练习
慕仙1126188
2019-10-02 21:48:50
<!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; display:none; } .border:hover div,.padding:hover div,.content:hover div{ display:block; } /*补充代码*/ .border a:hover{ background-clip:border-box; } .padding a:hover{ background-clip:padding-box; } .content a:hover{ 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-10-06
同学你好,效果实现的不对哦, 因为你这里的是给a设置hover样式的, 无法实现改变div的背景图片样式, 需要调整选择器, 通过兄弟选择器选择鼠标移入a链接的时候,给他的兄弟元素div设置background-clip属性哦
如果帮助到了你, 欢迎采纳!
祝学习愉快~~~~
相似问题