最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

css - Style background color of root React Javascript - Stack Overflow

programmeradmin5浏览0评论

Does anyone know how to style the root in React? I know it can be done in JQuery by executing the following;

$(":root").css("background-color", "yellow");

Does anyone know how to style the root in React? I know it can be done in JQuery by executing the following;

$(":root").css("background-color", "yellow");
Share Improve this question edited Dec 12, 2024 at 17:10 j08691 208k32 gold badges269 silver badges280 bronze badges asked Oct 17, 2018 at 13:24 Guy LepageGuy Lepage 951 gold badge3 silver badges12 bronze badges 1
  • 2 Why not just style your root ponent, instead of the root mount point? – Blue Commented Oct 17, 2018 at 13:25
Add a ment  | 

2 Answers 2

Reset to default 2

Here is an example,App is my root element.

import './App.css';
class App extends Component {

  render() {
    const backStyle = style({
      background: 'black'
    })
    return (
      <div className={backStyle}>
      ...
      </div>
    );
  }
}

export default App;

You define the css properties like background-color in App.css. And there are many ways to do that.

return (
  <div style={{background: black}}>
  ...
  </div>
);

Define the style of the root is quite similar.i.e

import './index.css';
import App from './App';

ReactDOM.render(<App />, document.getElementById('root'));

You can do one thing. In your index.html you can use style tags to style root div. It will do what you are trying to do. As all the ponents are loaded within the root wrapper, so it will be like a global style.

发布评论

评论列表(0)

  1. 暂无评论