简体   繁体   English

HTML CSS 更改区域上 Hover 上的 BG

[英]HTML CSS Change BG on Hover on Area

I would like to change the image depending on what area I hover.我想根据我 hover 的区域来更改图像。

Unfortunately, I have to realize it using only HTML/CSS.不幸的是,我必须仅使用 HTML/CSS 来实现它。 I have already read and understood similar amounts but I can't get the desired result.我已经阅读并理解了类似的数量,但我无法得到想要的结果。 Does anyone have an idea?有人有想法吗?

 body { background-color: white; justify-content: center; align-content: center; overflow: hidden; }.box { position: relative; width: 1044px; height: 461px; }.box.screen { position: absolute; top: 0; left: 0; opacity: 0; transition: 0.7s; } box.GER { background: url('worldmap.png'); } box.GER:hover { background: url("worldmap_ger.png"); }
 <div class="box"> <img src="worldmap.png" usemap="#image-map"> <map src="worldmap.png" name="image-map"> <div class="GER"> <area target="GER" alt="GER" title="GER" href="linkGER" coords="508,263,510,255,515,251,527,254,530,264,525,268,526,278,512,278,508,273" shape="poly"> </div>

You use wrong selector, need change to .box.GER instead of box.GER您使用了错误的选择器,需要更改为.box.GER而不是box.GER

 body { background-color: white; justify-content: center; align-content: center; overflow: hidden; }.box { position: relative; width: 1044px; height: 461px; }.box.screen { position: absolute; top: 0; left: 0; opacity: 0; transition: 0.7s; }.box.GER { background: url('https://pngimg.com/uploads/world_map/world_map_PNG28.png'); border: 1px solid red; height: 200px; }.box.GER:hover { background: url("https://w7.pngwing.com/pngs/944/256/png-transparent-world-map-globe-world-map-flat-earth-asia-miscellaneous-blue-world.png"); }
 <div class="box"> <map src="https://pngimg.com/uploads/world_map/world_map_PNG28.png" name="image-map"> <div class="GER"> <area target="GER" alt="GER" title="GER" href="linkGER" coords="508,263,510,255,515,251,527,254,530,264,525,268,526,278,512,278,508,273" shape="poly"> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM