简体   繁体   English

悬停时更改基本图像

[英]Change base image on hover

I want to change .product-image div when I click or hover on the small thumbnails only with HTML. 当我仅使用HTML单击或悬停在小缩略图上时,我想更改.product-image div。 Before I use a JavaScript code but I want to skip JavaScript method and leave only pure HTML. 在使用JavaScript代码之前,我想跳过JavaScript方法,只保留纯HTML。

Is there any way to can do this only with HTML? 有什么方法只能用HTML做到这一点吗?

I just want to say that the images will not have the same name like, instead the image name will be a variable, so every time when the page is loaded there will be other names for the images. 我只想说图像将不会具有相同的名称,而是图像名称将是一个变量,因此每次加载页面时,图像都会有其他名称。

Here is my code: 这是我的代码:

 ul,ol {list-style:none;} .product-img-box {float:left;} .product-img-box .product-image {width:300px; float: right;} .product-img-box .more-views li img {width:90px; } 
 <div class="product-img-box"> <div class="more-views" style="float:left"> <ul class="slides" id="slides"> <li><a rel="#" href="#"><img src="http://i64.tinypic.com/24cuyhk.jpg" alt=""></a></li> <li><a rel="#" href="#"><img src="http://i64.tinypic.com/23mamww.jpg" alt=""></a></li> <li><a rel="#" href="#"><img src="http://i63.tinypic.com/1zwyaux.jpg" alt=""></a></li> <li><a rel="#" href="#"><img src="http://i63.tinypic.com/1zmk0ag.jpg" alt=""></a></li> <li><a rel="#" href="#"><img src="http://i64.tinypic.com/espx68.jpg" alt=""></a></li> </ul> </div> <p class="product-image" style="float:right"> <a href="#"><img src="http://i64.tinypic.com/24cuyhk.jpg" alt="" id="mainImage"></a> </p> </div> 

Thank you so much 非常感谢

but is imposible for me to use href there, all that href will be populated automatically. 但我无法在此处使用href,所有href都将自动填充。

Then In this case you could try to use CSS :hover 然后,在这种情况下,您可以尝试使用CSS:hover

What I did is that when you hover the .grid1 it will look for the preceded( ~ ) element that is the .grid6 and then it will look for #img1 where the parent( > ) is .grid6 . 我所做的是,当你将鼠标悬停在.grid1它会寻找之前( ~那是)元素.grid6 ,然后它会寻找#img1如果母公司( > )是.grid6

.grid1:hover ~ .grid6>#img1{
  display:block;
}

Please see the sample code below. 请参阅下面的示例代码。

 html,body{ height:100%; width:100%; padding:0; margin:0; } .container{ margin-left:5%; margin-top:5%; display:grid; grid-template-columns: 15% 1fr; grid-template-rows: repeat(5, 1fr); justify-items: center; align-items: center; height:80%; width:80%; } .container img{ height:auto; width:100%; } .grid1, .grid2, .grid3, .grid4, .grid5{ height:100%; width:100%; } .grid6{ grid-row: 1 / 6; grid-column: 2 / 3; } .grid6 a{ display:none } .grid1:hover ~ .grid6>#img1{ display:block; } .grid2:hover ~ .grid6>#img2{ display:block; } .grid3:hover ~ .grid6>#img3{ display:block; } .grid4:hover ~ .grid6>#img4{ display:block; } .grid5:hover ~ .grid6>#img5{ display:block; } 
 <div class="container"> <div class="grid1"> <a rel="#" href="#img1"> <img src="http://i64.tinypic.com/24cuyhk.jpg" alt=""> </a> </div> <div class="grid2"> <a rel="#" href="#img2"> <img src="http://i64.tinypic.com/23mamww.jpg" alt=""> </a> </div> <div class="grid3"> <a rel="#" href="#img2"> <img src="http://i63.tinypic.com/1zwyaux.jpg" alt=""> </a> </div> <div class="grid4"> <a rel="#" href="#img2"> <img src="http://i63.tinypic.com/1zmk0ag.jpg" alt=""> </a> </div> <div class="grid5"> <a rel="#" href="#img2"> <img src="http://i64.tinypic.com/espx68.jpg" alt=""> </a> </div> <div class="grid6"> <a href="#" id="img1"> <img src="http://i64.tinypic.com/24cuyhk.jpg" alt=""> </a> <a href="#" id="img2"> <img src="http://i64.tinypic.com/23mamww.jpg" alt=""> </a> <a href="#" id="img3"> <img src="http://i63.tinypic.com/1zwyaux.jpg" alt=""> </a> <a href="#" id="img4"> <img src="http://i63.tinypic.com/1zmk0ag.jpg" alt=""> </a> <a href="#" id="img5"> <img src="http://i64.tinypic.com/espx68.jpg" alt=""> </a> </div> </div> </div> 

Hope this helps. 希望这可以帮助。

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

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