How to change pseudo-element child when parent is hovered over?

只谈情不闲聊 提交于 2021-01-27 14:31:01

问题


I'm trying to get an item that is a pseudo element to change when the parent is hovered over. The pseudo element here is .child:after. I know this works:

.parent:hover .child { 
   background: #FF0000; 
  }

But this does not seem to work:

.parent:hover .child:after { 
   background: #FF0000; 
  }

Any ideas? Thank you!!


回答1:


Try to add content:'' to ::after pseudo-class;

Also be aware that :after works with non-replaced elements (im, input, textarea, and so on) (refference: replaced elements.)

Additionally: pay attention to display property of .child:after selector.

Here you go with a working example https://jsfiddle.net/wq2edhf3/.



来源:https://stackoverflow.com/questions/31952652/how-to-change-pseudo-element-child-when-parent-is-hovered-over

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!