OK, so following up on the edits and looking into the related post there is a lot to unpack here. Between your original closed question and this new one with the edits, I see one (maybe two?) problems you are trying to solve:
- When you apply the filters, in Firefox the buttons lose their position.
- You would (maybe?) like the buttons to not be affected by the filter.
I've created a slightly modified snippets that works with your code and address both issues:
For the issue of button placement:
function change()
{
document.getElementsByTagName('html')[0].classList.toggle('new-theme');
}
html {
height: 100%; /* Fixes the buttons losing position in firefox */
}
.new-theme {
filter: invert(100%) hue-rotate(180deg);
-webkit-filter: invert(100%) hue-rotate(180deg);
-moz-filter: invert(100%) hue-rotate(180deg);
-o-filter: invert(100%) hue-rotate(180deg);
-ms-filter: invert(100%) hue-rotate(180deg);
}
#fixedbutton {
position: fixed;
bottom: 20px;
right: 20px;
}
h1{
color:blue;
}
#anotherfixedbutton {
position:fixed;
bottom:20px;
left: 20px
}
<html>
<head>
</head>
<body>
<h1> Some text </h1>
<button id="fixedbutton" onclick="change()">CLICKME</button>
<button id="anotherfixedbutton">please let me sleep me here firefox</button>
</body>
</html>
The solution here for the buttons losing their position on Firefox was to add height: 100%
to the html
element. A bit strange, but similar to Temani Afif's answer on the purported duplicated of your original question; basically, because the filter creates a new containing block context we need to make some adjustments.
For excluding the buttons from the filter effect:
function change()
{
document.getElementsByTagName('html')[0].classList.toggle('new-theme');
}
html {
height: 100%; /* Fixes the buttons losing position in firefox */
}
.new-theme {
filter: invert(100%) hue-rotate(180deg);
-webkit-filter: invert(100%) hue-rotate(180deg);
-moz-filter: invert(100%) hue-rotate(180deg);
-o-filter: invert(100%) hue-rotate(180deg);
-ms-filter: invert(100%) hue-rotate(180deg);
}
.new-theme #fixedbutton,
.new-theme #anotherfixedbutton {
filter: invert(100%) hue-rotate(180deg);
-webkit-filter: invert(100%) hue-rotate(180deg);
-moz-filter: invert(100%) hue-rotate(180deg);
-o-filter: invert(100%) hue-rotate(180deg);
-ms-filter: invert(100%) hue-rotate(180deg);
}
#fixedbutton {
position: fixed;
bottom: 20px;
right: 20px;
}
h1{
color:blue;
}
h2 {
color: orange;
}
#anotherfixedbutton {
position:fixed;
bottom:20px;
left: 20px
}
<html>
<head>
</head>
<body>
<h1> Some text </h1>
<h2> Some other text </h2>
<button id="fixedbutton" onclick="change()">CLICKME</button>
<button id="anotherfixedbutton">please let me sleep me here firefox</button>
</body>
</html>
Again, I'm not totally sure if this was an effect you were seeking. But regardless, the issue here is that the buttons have their color inverted not because they are selected by the .new-theme
selector, but because they are contained within the .new-theme
-classed element which is having the filter applied to it. However, because you are simply inverting the filters you are using, you can invert them again for those specific buttons when they are within a .new-theme
-classed element, returning them their original hues.