[英]Using CSS with React/JSX
This may be a very simple question but I cannot figure out how to use CSS with React. 这可能是一个非常简单的问题,但是我无法弄清楚如何在React中使用CSS。 I have heard of inline styles but I couldn't figure out how to get it to work. 我听说过内联样式,但是我不知道如何使它起作用。
More so, if I use CSS where do I apply it to considering all my HTML is JSX within the react class. 更重要的是,如果我使用CSS,那么在哪里将其应用于考虑我的所有HTML是javascript类中的JSX。 So I would not be able to do normal CSS ie 所以我将不能做普通的CSS即
.className{
}
One of my react classes contains this code: 我的react类之一包含以下代码:
render: function() {
return (
<div>
<h1> Todos </h1>
<form className="todoForm" onSubmit={this.handleSubmit}>
<input
type="text"
placeholder="Enter task"
value={this.state.text}
onChange={this.handleChange}
/>
<input
type="submit"
value="Submit todo"
/>
</form>
<h4> List of todos: </h4>
<ToDoList deleteItem={this.deleteItem} listItems={this.state.submittedValues}/>
</div>
);
How would I say make the input box in the form have a green background or how would I make the <h1> heading
blue in font? 我该怎么说表格中的输入框为绿色背景,或者如何使<h1> heading
蓝色? In CSS I would just have a css file link it to html and say: h1 { color: blue };
在CSS中,我只需要一个CSS文件将其链接到html,然后说: h1 { color: blue };
cant quite see it in react though? 不能完全看到它的反应吗?
use a className for input type="text" 使用className作为输入type =“ text”
<input type='text' className='exText' />
for Ur CSS .exText { background: 'green' } 用于Ur CSS .exText {背景:'绿色'}
please use className as a attributes to the component and use the components name with . 请使用className作为组件的属性,并使用组件名称。 if it is a className and # if its id. 如果是className,则为#(如果它是id)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.