1

Why can I not combine these into a single line, when I do it only effects the latter. On hover of .link, I want h3 and h4 to be color:white. Example:

This works, but I wanted to save a line of code by combining them.

.link:hover h3 {
 color: white;
}

.link:hover h4 {
color: white;
} 


However this does not work, it only effects the h3, and the h4 color:white gets applied before the hover

.link:hover h3, h4 {
color: white;
}
4

2 回答 2

8

您没有在悬停时应用第二个!

.link:hover h3 ,
.link:hover h4 {
    color: white;
} 
于 2013-09-06T18:21:13.460 回答
1

需要注意的是,如果您真的希望能够将样式应用于两者h3h4无需重复.link:hover,那么所有流行的 CSS 预处理器都支持该功能。以下适用于Sass(SCSS 语法)、LESSStylus

.link:hover {
    h3, h4 {
        color: white;
    }
}

编译成这个 CSS(可能格式不同):

.link:hover h3,
.link:hover h4 {
    color: white;
}
于 2013-09-06T19:33:30.970 回答