css - 悬停时向多个元素添加样式 - scss

标签 css sass

我目前有这段代码,当将鼠标悬停在页脚单元格上时,它会将页脚标题和副标题变为白色,并且有效:

.footer-cell {
    position: relative;
    display: table;
    height: 160px;

    &:hover .footer-title {  // footer-title line
        color: white;
    }

    &:hover .footer-subtitle {  // footer-subtitle line
        color: white;
    }
}

有什么方法可以组合页脚标题行和页脚副标题行,这样我就没有重复的代码了吗?我试过这个但它不起作用:

.footer-cell {
    position: relative;
    display: table;
    height: 160px;

    &:hover .footer-title, .footer-subtitle {
        color: white;
    }
}

最佳答案

只需将选择器包装在 :hover 类中:

.footer-cell {
    position: relative;
    display: table;
    height: 160px;

    &:hover{ 
        .footer-title, .footer-subtitle {
           color: white;
        }
    }
}

Compiles to this

关于css - 悬停时向多个元素添加样式 - scss,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40265760/

相关文章:

html - CSS nth-child(2n) 选择器选择所有 child

html - 在悬停时显示,但仅在悬停的元素上显示

html - 固定位置侧边栏溢出问题

css - 唯一 ID CSS |为什么我的造型在其他地方被采用?

tomcat - 无法在 CSS 上解析 SASS

javascript - Laravel Mix 突然停止编译 SCSS 并写入空文件

css - sass 看多个目录

css - 只显示主页中文章的开头

HTML/CSS : Nav bars on the left side of page

css - 下划线字体大小混合