gpt4 book ai didi

html - CSS选择器的优先级

转载 作者:太空宇宙 更新时间:2023-11-04 16:07:41 25 4
gpt4 key购买 nike

这是我的 HTML:

<input type='submit' class='clsname'>

此 CSS 为该输入制作了一个 blue 边框:Demo

input{
border: 1px solid red;
}
.clsname{
border: 1px solid blue;
}

但这会为该输入生成一个红色 边框:Demo

input[type='submit']{
border: 1px solid red;
}
.clsname{
border: 1px solid blue;
}

我不知 Prop 体为什么,但我知道这与选择器的优先级有关。我认为 input[type='submit'] 比 classname 有更高的优先级,但是 input 没有比 classname 更高的优先级。

现在我有一个这样的选择器:input[type='submit'] 我需要给类名更高的优先级。我怎样才能做到这一点?我的意思是这样的:

input[type='submit'] { }
.clsname { /* bigger priority here */ }

注意:我可以通过!important来做到这一点,但我想知道还有其他方法吗?因为推荐使用!important

最佳答案

这是特异性。阅读更多 here on W3 .

使用 input[type='submit'].clsname, .clsname 选择器。

这是 fiddle .

关于html - CSS选择器的优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36801374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com