question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Applying styles to DOM elements that aren't React components?

See original GitHub issue

I 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:closed
  • Created 8 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
gavingcommented, Jun 18, 2016

@Dattaya Thanks for this šŸ‘

2reactions
Dattayacommented, Jan 8, 2016

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 with imports, so I always use require. Also, for some reason, even require doesn’t work for me when it’s outside of the render method of a component. Try to load your global styles inside of the render of Html helper component or App component like so:

  render() {
    require('medium-editor/dist/css/medium-editor.css');
    require('medium-editor/dist/css/themes/bootstrap.css');

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 be extensions: ['css', 'less', 'scss'], In dev.config you most likely have css loader already: { test: /\.css$/, loader: 'style!css?sourceMap'} and your prod.config seems to be correct.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found