简体   繁体   English

不能同时放置超链接和一般兄弟组合器?

[英]Can't put hyperlink and general sibling combinator at the same time?

Hey guys I'm really new to css so I'll try to explain this the best I could. 嘿伙计我真的很新css所以我会尽力解释这个。

I'm trying to create an image hyperlink .link so that whenever I hover my mouse pointer over it, .link and .picture "changes" their image. 我试图创建一个图像的超链接。链路这样,每当我将鼠标悬停我的鼠标指针它。链路.picture“改变”自己的形象。 But I still want the hyperlink to be clickable. 但我仍然希望超链接可以点击。

 .picture { background-image: url('imageB1.jpg'); width: 100px; height: 100px; } .link { background-image: url('imageA1.jpg'); width: 100px; height: 100px; } .link:hover { background-image: url('imageA2.jpg'); } .link:hover+.picture { background-image: url('imageB2.jpg'); } 
 <a href="destination.html"> <div class="link"></div> </a> <div class="picture"></div> 

The problem with my code is that while .link may be clickable, picture doesn't change its background-image when I hover on .link . 我的代码的问题是,虽然.link可能是可点击的,但当我将鼠标悬停在.link上时, 图片不会改变其背景图像。 I hope someone can help me. 我希望有一个人可以帮助我。 Thanks in advance! 提前致谢!

 Try this one 
 <a href="destination.html" >
 <div class="link">
  </div>
  </a>
  <div class="picture"></div>



 .picture {
 background-image: url('imageB1.jpg');
 width: 100px;
 height: 100px;
  display:none;
  }

.link {
background-image: url('imageA1.jpg');
width: 100px;
height: 100px;
display:block;
 }

 .link:hover {
  content: url('imageA2.jpg');
  }

   .link:hover+.picture {
   background-image: url('imageB2.jpg');
     }

I am not sure whether general sibling combinaton can be select from one sibling but you can do it using different way. 我不确定是否可以从一个兄弟姐妹中选择一般兄弟姐妹组合,但你可以用不同的方式来做。

As wrapping both element( a and div ) to another div element then you can select Selects all .pictures classes where the parent is a .container class like the below. 在将元素( a和div )包装到另一个div元素时,您可以选择选择所有.pictures类,其中父类是.container类,如下所示。

.picture {
  background-image: url('DSC_0268.jpg');
  width: 100px;
  height: 100px;
}

.link {
  background-image: url('DSC_0268.jpg');
  width: 100px;
  height: 100px;
}

.link:hover {
  background-image: url('db 2 assignment schedule.png');
}

.container:hover > .picture {
  background-image: url('db 2 assignment schedule.png');
}
</style>

<div class="container">
<a href="destination.html">
  <div class="link"></div>
</a>
<div class="picture"></div>
</div>

look for selectors that you can use in css. 寻找可以在css中使用的选择器。 css selectors css选择器

I think this will met what you want to do!. 我想这会满足你想要做的!

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

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