Dynamically added classes are not inserted in css
See original GitHub issueI have a menu that when opened gets the menu-open class (via javascript).
I want this menu to have 10px margin only if it has the menu-open class.
<style>
/ * It works but it's not what I want * /
li.nav-item
{
margin-bottom: 10px;
}
/* Does not work */
li.nav-item.menu-open, li.menu-open
{
margin-bottom: 10px;
}
</style>
I am using Svelte 3.9.1
Thanks.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
CSS Styling didn't get applied when class added dynamically ...
"currentDay" is the class I wanted and it is now added. Anyhow, I have a css for currentDay in g.html which says:
Read more >Dynamic style - manipulating CSS with JavaScript - W3C Wiki
createElement function to create a new style element. This is useful when you want to give site visitors the option of changing your...
Read more >Make Your CSS Dynamic with CSS Custom Properties - Toptal
Explore CSS custom properties and find out how they can be used to make better, more dynamic stylesheets.
Read more >Dynamically add CSS class with JavaScript - Includehelp.com
In this post, we will learn how to dynamically add CSS class with JavaScript code. It is useful to add interactive dynamic functionality?...
Read more >How to Dynamically Add/Remove Table Rows using jQuery
There are two issues. Firstly, as each row is being added dynamically, we cannot detect the click of a remove button directly by...
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
I just mentioned both options so that the test could be done.
I noticed that in some cases, if the css path is set completely, the style works, otherwise not (this applies to cases where css overwriting is required).
The way you did it works, but when trying to change via javascript, it doesn’t work, eg:
someElement.classList.add ('menu-open');
I thought about the possibility that the compiler is ignoring unused css (initially) inside the component.
Thanks all!