【发布时间】:2019-09-28 11:46:30
【问题描述】:
当用户单击/引发事件时,我想对除一个 ID(或类)之外的 html 页面的每个元素应用效果。我该怎么做?我尝试使用 :not() 选择器,但我认为它不适合它。
MWE:
index.html
<html>
<head>
<link disabled id="toggle_element" rel="stylesheet" href="./new_theme.css">
<link rel="stylesheet" href="./style.css">
<script src="./script.js" type="text/javascript"></script>
</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>
style.css
html {
}
#fixedbutton {
position: fixed;
bottom: 20px;
right: 20px;
}
h1{
color:blue;
}
#anotherfixedbutton {
position:fixed;
bottom:20px;
left: 20px
}
new_theme.css
html {
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);
}
script.js
function change()
{
document.getElementById("toggle_element").disabled = false;
}
我想从过滤器的效果中排除固定按钮。 此示例运行良好,在 Chrome 和 Safari 中没有问题,但在 Firefox 中,按钮只是失去了它们的位置。
【问题讨论】:
-
只为那些你想要应用效果的元素添加一个类
-
@HabibMhamadi:一个大网站的东西太多了,做不到。
-
我已根据您更新的代码更新了我的答案。
标签: html css css-selectors