dash icon indicating copy to clipboard operation
dash copied to clipboard

Local CSS is overridden by React-generated CSS

Open EBoisseauSierra opened this issue 6 years ago • 14 comments

Context

I'm trying to style various DCC elements — say multi-value dropdowns.

Problem

I am using Dash v0.31.0.

I add a css file to my project containing:

.Select--multi .Select-value {
    background-color:#df0a0b;
}

I know the CSS is loaded as other rules (e.g. affecting h1) take effect. However, for the dropdown, my own styles are overridden by the React select .ccs file — i.e. the file starting with:

/**
 * React Select
 * ============
 * Created by Jed Watson and Joss Mackison for KeystoneJS, http://www.keystonejs.com/
 * https://twitter.com/jedwatson https://twitter.com/jossmackison https://twitter.com/keystonejs
 * MIT License: https://github.com/JedWatson/react-select
*/
.Select {
  position: relative;
}
…
.Select--multi .Select-value {
  background-color: #ebf5ff;
  /* Fallback color for IE 8 */
  background-color: rgba(0, 126, 255, 0.08);
  border-radius: 2px;
  border: 1px solid #c2e0ff;
  /* Fallback color for IE 8 */
  border: 1px solid rgba(0, 126, 255, 0.24);
  color: #007eff;
  display: inline-block;
  font-size: 0.9em;
  line-height: 1.4;
  margin-left: 5px;
  margin-top: 5px;
  vertical-align: top;
}
…

The latter is indeed passed as "inline": screenshot from 2018-12-06 16-50-03

Question

How to enforce my CSS?

EBoisseauSierra avatar Dec 06 '18 17:12 EBoisseauSierra

Quick and dirty fix: replace all .Select with div.Select to gain higher priority.

EBoisseauSierra avatar Dec 06 '18 17:12 EBoisseauSierra

What version of dash-core-components are you using? In https://github.com/plotly/dash-core-components/pull/382 we fixed the issue where user supplied styles weren't overriding the React included styles.

valentijnnieman avatar Dec 07 '18 19:12 valentijnnieman

@valentijnnieman indeed, I thought it would have been solved. But I made sure I'm using v0.39.0…

$ pip show dash-core-components
Name: dash-core-components
Version: 0.39.0
...

EBoisseauSierra avatar Dec 10 '18 14:12 EBoisseauSierra

Same behavior in v0.42.1

anandcu3 avatar Mar 14 '19 08:03 anandcu3

Same behavior in 0.45.0 only with imported dash_table

mamay13 avatar Apr 11 '19 11:04 mamay13

Same here with dash 1.9.1 using dash_table. Custom CSS is applied correctly on page load, however I have dropdowns in one tab and tables in another. Switching to the table tab causes custom css to be overridde once I switch back.

jjaraalm avatar Apr 01 '20 16:04 jjaraalm

I also have this issue. Any solutions yet? I can't find the part in my CSS which controls the dropdown menu colors.

elastufka avatar Mar 11 '21 12:03 elastufka

I am having the exact same issue but with dash_table. Any solutions yet?

AP2008 avatar Mar 26 '21 00:03 AP2008

Same issue with dcc.tabs. The actual example that you provide on your website: Styling the Tabs component with CSS Classes contains this issue. Any solutions yet?

Geometrein avatar Aug 06 '21 08:08 Geometrein

Same behavior with dash-core-components ver. 2.0.0 React override local CSS of dropdown only when a dash_table is present.

@EBoisseauSierra 's trick works nicely

Quick and dirty fix: replace all .Select with div.Select to gain higher priority

Xzyon avatar Dec 16 '22 08:12 Xzyon

I have the same problem with .Select--multi .Select-value being overwritten by react-select

lance-noel avatar Apr 19 '23 18:04 lance-noel

Hello, Is there any update on a permanent fix for this?

Thanks

ndretex avatar Dec 18 '23 13:12 ndretex

@ndretex are you referring to a CSS styling problem related to Dash Core Components or the Dash DataTable? Can you share your code or sample code that recreates this problem?

Coding-with-Adam avatar Dec 21 '23 16:12 Coding-with-Adam

Another quick and dirty fix, add !important to the css property you want to override

at1047 avatar Mar 18 '24 21:03 at1047

Hi - we are tidying up stale issues and PRs in Plotly's public repositories so that we can focus on things that are most important to our community. If this issue is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. (Please note that we will give priority to reports that include a short reproducible example.) If you'd like to submit a PR, we'd be happy to prioritize a review, and if it's a request for tech support, please post in our community forum. Thank you - @gvwilson

gvwilson avatar Jul 25 '24 13:07 gvwilson