1
I am implementing a high contrast mode, and for that, I am using the following structure:
To draw the high contrast:
<li><a href="#" class="seleciona-estilo" data-classe="classe-azul">MODO ESCURO</a></li>
Javascript that adds CSS
<script>
$(".seleciona-estilo").on("click", function(e){
e.preventDefault();
$("link").attr("href", "ei-modo-escuro.css");
});
</script>
My question is: when I click on the "Dark Mode" button, the page loads the CSS in question and everything is as planned, but the other previous CSS settings are lost (such as fonts, positioning and the like...). All I want is for "Dark Mode" to replace the colors of background-color and color, without overriding all others that I do not wish to change. This is possible?
Thanks in advance! =]
You can post your code complete with the css styles.
– Wendell
If it’s not a lot of CSS, you can create two classes, . clear and . dark in CSS. When you click, you use $("link"). addClass( "dark"); and $("outro_link"). removeClass( "dark"); or you can use . css("background", "#000");
– Cleverson
The styles in common in the two "themes" should be placed in a css file that could be called for example ".css structure", for each new "theme" would have to create a separate css file where in them would be added only the individual styles of each, in your case, only color styles (background-color, color). Color css would be loaded dynamically by jquery. Doing so, the structure will not change since it would be loading the ".css structure" that is common for both, what would change would only be the colors of your application, in the individual themes.
– Thiago Yoithi