In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to set the DOM style in the react component, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
1. Inline style
To add an inline style to a virtual dom, you need to use the expression to pass in the style object to implement the
An inline style needs to be written to a style object, and the location of this style object can be placed in many places
For example: in the render function, on the component prototype, in the outer chain js file
Note: the two parentheses here, the first indicates that we have inserted JS in the JSX, and the second is the parenthesis of the object
Hello world
2. Use class
React recommends that we use inline style because React feels that each component is a separate whole.
In fact, we are still adding a lot of class names to elements in most cases, but it is important to note that class needs to be written as className (because, after all, you are writing class js code, you will receive js rules now, and class is the keyword)
Import React, {Component} from 'react'1. External introduction of defined style import styles from'. / style.css'class ClassStyle extends Component {render () {/ / js logic let className = cx ({font: false}) return (hello style
World)}} export default ClassStyle3, classNames add different styles under different conditions
Sometimes you need to add different styles according to different conditions, such as: completion status, completion is green, unfinished is red. In this case, we recommend using the package classnames:
Objective:
An error will be reported due to the native dynamic addition of multiple className to react.
Import style from'. / style.css' props.inputColor | | "blue"}; border-radius: 3px; `; export {Input}
Display
Import React, {Component} from 'react'import {Input} from'. / Styles'class App extends Component {render () {return ();}} export default App is all the content of the article "how to set DOM style in react components". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.