如何在组件React中注入CSS [英] How inject CSS in Component React

查看:127
本文介绍了如何在组件React中注入CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将一个html文件转换为一个7段LED组件,我从index.css导入了css文件,但是自index.css以来我不知道如何注入样式

I've converted a html file to a component is a 7 segment LED, I imported the css file from index.css, but I don't know how inject the styles since index.css

我试图通过值来注入样式,但是css语法发生了变化,并且组件无法识别
我想知道是否存在一种无需修改即可传递样式的方法css文件

I tried to inject the styles by means of values, but the css syntax changes and the component does not recognize I want to know if there is a way to pass the styles without modifying the css file

import React from 'react'
import styles from './index.css'

const Display = () =>{
  return(
    <div id="vertical-center">
        <div id="clock-container">
            <div id="display-1" className="display-container display-size-12 display-no-0">
                <div className="segment-x segment-a"><span className="segment-border"></span></div>
                <div className="segment-y segment-b"><span className="segment-border"></span></div>
                <div className="segment-y segment-c"><span className="segment-border"></span></div>
                <div className="segment-x segment-d"><span className="segment-border"></span></div>
                <div className="segment-y segment-e"><span className="segment-border"></span></div>
                <div className="segment-y segment-f"><span className="segment-border"></span></div>
                <div className="segment-x segment-g"><span className="segment-border"></span></div>
            </div>
        </div>
    </div>
  )
}

export default Display

我如何从
index.css中注入样式:

How I could inject styles from this index.css:

.clear {
    clear: both;
}

.display-container.display-size-12 {
    margin-bottom: 24px;
}


.display-container {
    position: relative;
    margin-right: 24px;
    float: left;
}

.display-container div.segment-x,
.display-container div.segment-y {
    position: absolute;
}

.display-container span.segment-border {
    display: block;
    position: absolute;
}

.display-container.display-size-12 {
    width: 122px;
    height: 220px;
}

.display-container.display-size-12 .segment-x {
    width: 72px;
    left: 13px;
    border-bottom: 12px solid #000;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
}

.display-container.display-size-12 .segment-x .segment-border {
    top: 12px;
    left: -12px;
    right: -12px;
    border-top: 12px solid #000;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
}

.display-container.display-size-12 .segment-y {
    height: 72px;
    width: 0;
    border-right: 12px solid #000;
    border-top: 12px solid transparent;
    border-bottom: 12px solid transparent;
}

.display-container.display-size-12 .segment-y .segment-border {
    position: relative;
    left: 12px;
    height: 72px;
    margin-top: -12px;
    border-left: 12px solid #000;
    border-top: 12px solid transparent;
    border-bottom: 12px solid transparent;
}

.display-container.display-size-12 .segment-a {
    top: 0;
}

.display-container.display-size-12 .segment-b {
    top: 13px;
    left: 98px;
}

.display-container.display-size-12 .segment-c {
    top: 111px;
    left: 98px;
}

.display-container.display-size-12 .segment-d {
    top: 196px;
}

.display-container.display-size-12 .segment-e {
    top: 111px;
    left: 0px;
}

.display-container.display-size-12 .segment-f {
    top: 13px;
    left: 0px;
}

.display-container.display-size-12 .segment-g {
    top: 98px;
}

.display-no-0 .segment-g {
    /*display: none;*/
    opacity: 0.1;
}

#vertical-center {
    position: absolute;
    height: 0;
    top: 50%;
    left: 50%
}

#clock-container {
    margin-top: -110px;
    margin-left: -462px;
    width: 924px;
    height: 220px;
}


推荐答案

您应使用 style 带花括号,而不是 className ...

You should use style with curly braces instead of className...

这篇关于如何在组件React中注入CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆