【问题标题】:How to Style Elements with Component-Level CSS using Style Loaders?如何使用样式加载器为组件级 CSS 设置样式?
【发布时间】:2018-04-21 21:27:26
【问题描述】:

所以对于我的 create-react-app,我使用样式加载器来使用组件级 CSS,如下所示:

:local(.form) {
    max-width: 800px;
    min-height: 400px;
    margin: 0 auto;
    background-color: white;
    padding: 50px 35px;
    box-shadow: 0 0 2px 0 rgba(0,0,0,0.12), 0 2px 2px 0 rgba(0,0,0,0.12);
    border-radius: 50px;
}

但是,我该怎么做:

nav {
    line-height: 45px;
    height: 45px;
    background-color: white;
}

    /* The icon of our app */
    nav a .library-music {
        line-height: 45px;
        height: 45px;
        color: orange;
        font-size: 30px;
    }

你看到问题了吗?我不能做 ":local(nav a .library-music)。换句话说,将本地化 CSS 应用于非类元素的正确语法或方法是什么?

提前致谢,

【问题讨论】:

    标签: javascript css reactjs scope create-react-app


    【解决方案1】:
    nav a :local(.library-music) {
        line-height: 45px;
        height: 45px;
        color: orange;
        font-size: 30px;
    }
    

    您的nava 标签不受css 编译器的影响,因此您只需将:local() 修饰符应用于类名即可。

    【讨论】:

    • 如果是多个类,那就是 :local(class1) :local(class2) { ... } 对吗?
    猜你喜欢
    • 1970-01-01
    • 2021-09-20
    • 1970-01-01
    • 2018-07-30
    • 1970-01-01
    • 2018-08-05
    • 2016-07-30
    • 2013-12-11
    • 1970-01-01
    相关资源
    最近更新 更多