Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 悬停父元素时如何更改子元素的不透明度_Html_Css - Fatal编程技术网

Html 悬停父元素时如何更改子元素的不透明度

Html 悬停父元素时如何更改子元素的不透明度,html,css,Html,Css,我想在父div悬停时更改子div图像的不透明度。如何在CSS中实现这一点 <div class="parent"> <div class="child"> <img src="" alt="" height="" width=""> </div> </div> 使用和更改img: 或者,如果要更改while子div的不透明度,则: .parent:hover .child { opacity:

我想在父div悬停时更改子div图像的不透明度。如何在CSS中实现这一点

<div class="parent">
    <div class="child">
        <img src="" alt="" height="" width="">
    </div>
</div>

使用和更改img:

或者,如果要更改while子div的不透明度,则:

.parent:hover .child {
    opacity: 0.8;
}
提琴链样本-


您可以这样做:

.parent{
背景:红色;
填充:30px;
}
.parent:悬停.child{
不透明度:0.3
}
.孩子{
背景:蓝色;
填充:30px;
}


不要告诉我你在搜索时什么也没找到@Temaniaff如果没有片段、没有解释,并且对于这个问题难度达到75分的公认答案,我无法理解。而且它甚至不能准确回答问题<当父div悬停时,code>更改子div图像的不透明度,这应该在
中转换。父:悬停。子img{opacity:0.7}
@MihaiT祝你好运,找到那些鼓励反复询问如此琐碎和明显问题的选民;)
.parent:hover .child {
    opacity: 0.8;
}
.parent {
  width: 300px;
  height: 300px;
  background: red
}
.child {
  width: 100px;
  height: 100px;
  background: green
}
.parent:hover .child {
  opacity: .5
}