Dashboard Dropdown with custom CSS

I like using the Dashboard widgets, but I don't always like the default appearance. I've explored several posts on this forum, which change the appearance by using custom css
...so I had a go, using the Chrome browser inspection tool.

The dropdown widget seems to be one of the more complex structures. In trying to change "color" and "background-color" I found 5 classes in the default theme which overrode what I was wanting to change. In fact the only thing that wasn't overridden from "MyDropdown" was font-size.

In posts I saw from people like @hotNipi and @jbudd, they had overrides starting with .mdcontent, .mdcard etc. but I couldn't get anything to work unless I started with .nr-dashboard-theme.

I feel I'm missing something, and that this could be simplified. Anyone care to take a look?
Don't be alarmed at the ugly colors I've used. I wanted a diverse, contrasting selection so I could see what each one did. I would love to see a css file with all the dashboard style classes. Maybe we could Wiki one?

I am using node-red 2.1.5 and node-red-dashboard 3.4.0

<style> 
/* Customised css for dashboard dropdown widget. 
   Classes discovered by Inspecting Web page in Chrome browser.
   MyDropdown Class specified in dropdown widget could only change the font size
   other entries were overwritten.
   Discovered 5 other elements of the dropdown that had preset color attributes.
   The colors shown here are deliberately contrasting (ugly) so I could identify them at runtime :)
*/

body.nr-dashboard-theme md-content md-card {   /* default - no selections */
    background-color: #F433FF; /* Bright pink*/
    color: #64E986; /* green */
}

.nr-dashboard-theme md-select-menu md-option[selected] { /* selected option in dropdown */
    color: purple !important;
    background-color: silver !important;
}


.nr-dashboard-theme md-select-menu md-option {  /* unselected (default) in dropdown */
    background-color: lime;
    color: red;
}

.nr-dashboard-theme md-select-menu md-option:hover { /* when hovering over an item in the dropdown list */ 
    background-color: orange !important;
    color: green !important;
}


/* selected item from list with underline (border) */
.nr-dashboard-theme .nr-dashboard-dropdown md-select .md-select-value, .nr-dashboard-theme .nr-dashboard-dropdown md-select .md-select-value.md-select-placeholder {
    color: yellow;
    border-color: pink;
    border-bottom-width: 1px;
    padding: 0px 2px;
}


.MyDropdown {
    font-size: 24px;
}
</style>

Here's the short example flow:

[{"id":"d0d1f08b.852d6","type":"tab","label":"Custom Dropdown Example","disabled":false,"info":""},{"id":"cb41e652.188c9","type":"ui_dropdown","z":"d0d1f08b.852d6","name":"","label":"Dropdown","tooltip":"","place":"Select an Option","group":"ca2272c3.e8396","order":4,"width":0,"height":0,"passthru":true,"multiple":false,"options":[{"label":"Option 1","value":"option1","type":"str"},{"label":"Option 2","value":"option2","type":"str"},{"label":"Option 3","value":"option3","type":"str"}],"payload":"","topic":"","topicType":"str","className":"MyDropdown","x":200,"y":120,"wires":[["ef47c6d2.779a78"]]},{"id":"ef47c6d2.779a78","type":"debug","z":"d0d1f08b.852d6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":400,"y":120,"wires":[]},{"id":"3388f9fcd5b845d6","type":"ui_template","z":"d0d1f08b.852d6","group":"ca2272c3.e8396","name":"","order":5,"width":0,"height":0,"format":"<style> \n/* Customised css for dashboard dropdown widget. \n   Classes discovered by Inspecting Web page in Chrome browser.\n   MyDropdown Class specified in dropdown widget could only change the font size\n   other entries were overwritten.\n   Discovered 5 other elements of the dropdown that had preset color attributes.\n   The colors shown here are deliberately contrasting (ugly) so I could identify them at runtime :)\n*/\n\nbody.nr-dashboard-theme md-content md-card {   /* default - no selections */\n    background-color: #F433FF; /* Bright pink*/\n    color: #64E986; /* green */\n}\n\n.nr-dashboard-theme md-select-menu md-option[selected] { /* selected option in dropdown */\n    color: purple !important;\n    background-color: silver !important;\n}\n\n\n.nr-dashboard-theme md-select-menu md-option {  /* unselected (default) in dropdown */\n    background-color: lime;\n    color: red;\n}\n\n.nr-dashboard-theme md-select-menu md-option:hover { /* when hovering over an item in the dropdown list */ \n    background-color: orange !important;\n    color: green !important;\n}\n\n\n/* selected item from list with underline (border) */\n.nr-dashboard-theme .nr-dashboard-dropdown md-select .md-select-value, .nr-dashboard-theme .nr-dashboard-dropdown md-select .md-select-value.md-select-placeholder {\n    color: yellow;\n    border-color: pink;\n    border-bottom-width: 1px;\n    padding: 0px 2px;\n}\n\n\n.MyDropdown {\n    font-size: 24px;\n}\n</style>\n","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"MyDropdown","x":210,"y":200,"wires":[[]]},{"id":"ca2272c3.e8396","type":"ui_group","name":"Group 1","tab":"8e4884bb.ff1388","order":1,"disp":true,"width":6},{"id":"8e4884bb.ff1388","type":"ui_tab","name":"Button and Style testing","icon":"dashboard","order":11,"disabled":false,"hidden":false}]

Any reason why you don't have NR 3.0.2 ?

The element containing the dropdown seems to be div.nr-dashboard-dropdown, so I would expect to be able to style it from there downwards.
But after a bit of experimenting, I agree with you that it's a particularly difficult widget to style. Well done for getting as far as you did.

No magenta is too much in a web page! :upside_down_face:

1 Like

Not really. Here's one example of dropdown styling I have shared some time ago ...

<style id="dashboard-styles-override">
   .nr-dashboard-theme md-select-menu md-option {
        background-color: var(--nr-dashboard-groupBorderColor);
        color: #eeeeee;
        height: 29px;
       /* border-radius: 14px;*/
        margin-left: 10px;
        margin-right: 10px;
        margin-top: 2px;
        box-shadow: 0 0 6px 6px #24202133;
        transition: 0.3s;
    }
    .nr-dashboard-theme md-select-menu md-option[selected] {
        color: var(--nr-dashboard-widgetTextColor) !important;
        background-color: var(--nr-dashboard-widgetColor) !important;
    }
    .nr-dashboard-theme md-select-menu md-option:nth-child(even) {
        background-color: var(--nr-dashboard-groupBorderColor);
        opacity:0.8;
    }
    .nr-dashboard-theme md-select-menu md-option:last-child {
       margin-bottom: 8px;
    }
    .nr-dashboard-theme md-select-menu md-option:hover {
        background-color: var(--nr-dashboard-widgetBackgroundColor) !important;
        padding-left: 24px;
    }
    .nr-dashboard-theme md-select-menu md-option > .md-ripple-container{
        /* border-radius: 14px;*/
    }
</style

You'll find the selectors quite similar.
It may help if you take a little time to learn about the CSS selectors. CSS Selectors Reference Yes, it is quite of stuff but at least with basics learned, you'll understand an can read the CSS more easily. You'll spend less time on "trial'n'error".

33722 lines of CSS. :smiley:
With developer tools, go to the "Sources" tab, find "app.min.css", (use pretty print option {} at the bottom bar of the content panel) and explore the contents.

Thanks for the encouragement. Would NR 3.0.2 improve things in this regard? I've often found that upgrades cause issues, so I tend to leave them until I perceive a benefit...or else I'm just lazy.

Having said that, I only recently updated the dashboard to 3.4.0 so that I could use the new "Class" attribute in the widget. I was disappointed to find that almost everything I tried to add to "MyDropdown" was overridden. Made the new Class attribute almost superfluous.
:confused:

Thanks, I will try your example. I have been using w3schools and w3docs and developer.mozilla, to learn more about using classes in styles, selectors, specificity, !important etc.

I prefer not to try and reinvent the dashboard widgets' functionality, which are tried and tested, but I feel that changing the default appearance shouldn't be this hard. I will keep plugging away at the css though.

I've found app.min.css and app.min.less, but I'm not sure about "developer tools"(Notepad++ or something?). If I can at least document the most useful dashboard classes and what they do, I think that could be useful to others.

Thanks for taking the time to look at this. :+1:

I only recently updated the dashboard to 3.4.0 so that I could use the new "Class" attribute in the widget. I was disappointed to find that almost everything I tried to add to "MyDropdown" was overridden. Made the new Class attribute almost superfluous.

Can you give some more detail about this, and a flow to illustrate it?

Of course the className code was added in to existing dashboard widgets so it may not work well with all widget types.

I posted an example of changing widget style using className at https://discourse.nodered.org/t/dynamic-css-changes-in-dashboard-v3beta/50866 but it does not include a dropdown.

For dropdown the added className can't do much cos the actual dropdown with it's items when opened is independent div added as child of document body without any connection to the class got from the CSS option. Only elements of the closed state dropdown can be reached.

1 Like

Thanks for the example. I really like the technique of putting different styles in separate ui-template widgets and applying them by injecting the className, rather than having them all in one css widget.

I noticed that the syntax you used was different to what I had "scraped" and what @hotNipi used in his example. I liked that it was shorter, but I couldn't get it to work outside of your example.
e.g.

md-card.nr-dashboard-text.round {
    border-radius: 10px;
    color: darkred;
}

vs.

.nr-dashboard-theme md-select-menu md-option {  /* unselected (default) in dropdown */
    background-color: lime;
    color: red;
}

The latter also seems to correlate with the format in app.min.css so I can see how it is a direct replacement (override). What do you think? Pros& Cons?

Ok this is starting to make sense.

I had a look through the app.min.css file but found that the app.min.less file seems to be a simplified subset, and a more manageable size. Since my ambition is only to tweak colors and sizes, I am going to work on documenting the more common elements from the app.min.less file.
I'd like to also document the overall hierarchy of the common Angular elements like md-card, md-button, md-select etc. There's probably a way to split this out automatically, but that's beyond my skills at this point.

Thanks for your example too. after looking at the app.min.css file I was able to see how you tied in the variables from that, such as:

    .nr-dashboard-theme md-select-menu md-option:hover {
        background-color: var(--nr-dashboard-widgetBackgroundColor) !important;
        padding-left: 24px;
    }

Thanks again for the lessons learnt. It will take me some time to document, but I will share back as I go.

I really don't know particularly because the two snippets above are for different widget types.

However, the example I posted was something I tried when dashboard v3, with the className feature was still in beta so I was feeling my way.
And unlike you I have never extracted and compared the defaults from app.min.css so the chances of your approach being better than mine are pretty high!

I'd be interested to know how you scraped app.min.css.

ps Bear in mind that the dashboard uses a deprecated version of angular js so your efforts to document customising widgets may have a relatively short useful lifespan.
I guess that Dashboard itself will be come deprecated, after which there may be no "official" dashboard add-on

Initially I just used a standard dropdown and from the running dashboard I used the Chrome "Inspect" to look at the structure. I copied and pasted what I found, and used it to make my overrides. After @hotNipi's post I found the app.min.css and app.min.less files on github.
node-red dashboard css

1 Like

Fair enough. For me it's more of a learning path. I learn better when I have a problem to solve, and digging into css, classes, overrides is all useful for me.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.