html - 选择具有特定样式的元素?

标签 html css

是否可以使用 CSS 选择具有特定样式的元素? 就像...所有具有style="position:fixed;"的img

我的意思是 - 根据元素的样式而不是类或 id 选择元素。

最佳答案

我实际上会使用那个:

[style~="position:fixed;"]{
  /* whatever */
}

参见说明here

因此它将捕获样式中具有 position:fixed; 的所有元素(因为它们也可能具有其他样式属性)

但是如果 position 属性没有写在 HTML 中,选择器将不会选择它们。为此,您必须使用 JQuery。阅读 here

关于html - 选择具有特定样式的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19230338/

相关文章:

css - 连续 4 个 Div block ,每个 block 中有 2 个 div

CSS 搜索框如何保持响应

html - 有没有办法在嵌入网页时隐藏 SVG 文件/xml 的内容?

jquery - WordPress wpaudio soundmanager 插件的备用播放/暂停按钮

javascript - 下拉菜单 : drop down lists horizontal underneath main menu

html - 在 CSS 中,如何使背景颜色保持静态,从而在滚动时不会出现渐变变化?

html - 我怎么能不隐藏导航栏中的所有 ul,在按钮下?

html - react 分页样式

html - 如何处理DIV位置和高度

javascript - document.getElementById ("id").style.display = 'hidden' ;不工作