如果我有这样的标签
<div id='testdiv' style='height:300px;'></div>
我怎样才能写一个 css 规则说
select tag with id
testdiv
where it contains a style attribute that has height property whose value is less than 400px
这可能吗?
最佳答案
这在当前的 CSS 标准中是不可能的。 CSS4
可能包含一个选择器,但那是在遥远的 future 。然而,使用 JavaScript 或 jQuery 是可能的。
必须注意,ID 必须是唯一的。如果您想使用相同的名称,则应使用类。
在 jQuery 中,filter
函数应该可以解决这个问题。
var smallDivs = $(".test-div").filter(function() {
return $(this).css("height") < 400;
});
在 SASS 中也可以,您可以在其中创建函数。
关于css - 如何在 css3 选择器上放置小于运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34598009/