Applying styles to DOM elements that aren't React components?
See original GitHub issueI like the idea that I should have
const styles = require('./someStyle.scss');
return (<Panel className={styles.aClass}>...);
but in practice this isnāt helpful when I want to apply styles to DOM elements that arenāt react components.
In my scenario I am using react-bootstrap
and want to style the DOM tag <div class="body-panel">
, but only have access to a <Panel>
react component where the className only applies to the parent DOM element of the body-panel
div.
When I try to do something like this:
.aClass {
.panel-body {
padding: 15px 0px 0px 0px;
}
}
No style is applied. How can I make this work? Thanks
Issue Analytics
- State:
- Created 8 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
How To Style React Components | DigitalOcean
In this tutorial, you'll learn three different ways to style React components: plain Cascading Style Sheets (CSS), inline styles withĀ ...
Read more >Style React Components: 7 Ways Compared - SitePoint
There are a number of ways to style React components. Choosing the right method for styling components isn't a perfect absolute.
Read more >React bootstrap not styling my react components
Webpack; React & React DOM. I'm trying to setup Bootstrap styles. I followed this tutorial along but modified it to suit Typescript:.
Read more >DOM Elements - React
To specify a CSS class, use the className attribute. This applies to all regular DOM and SVG elements like <div> , <a> ,...
Read more >Solving the React Error: Not Picking Up CSS Style | Pluralsight
1import React, {Component} from 'react'; 2import ReactDOM from 'react-dom'; 3import '../CSS_Files/style.css';. javascript.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Dattaya Thanks for this š
I havenāt encountered these problems, yet. There are few things I have in mind you could try. Firstly, I think
webpack-isomorphic-tools
doesnāt work that well withimport
s, so I always userequire
. Also, for some reason, evenrequire
doesnāt work for me when itās outside of therender
method of a component. Try to load your global styles inside of therender
ofHtml
helper component orApp
component like so:This code is from my
Editable
component and I can see the styles are extracted properly in the prod mode. Also check you config files, this line https://github.com/erikras/react-redux-universal-hot-example/blob/master/webpack/webpack-isomorphic-tools.js#L65 should beextensions: ['css', 'less', 'scss'],
Indev.config
you most likely have css loader already:{ test: /\.css$/, loader: 'style!css?sourceMap'}
and yourprod.config
seems to be correct.