简体   繁体   English

将Bootstrap CSS类应用于给定类型的所有HTML元素

[英]Apply Bootstrap CSS class to all HTML elements of given type

I want to set the Bootstrap btn class to all <button> elements without doing it manually on every button. 我想将Bootstrap btn类设置为所有<button>元素,而无需在每个按钮上手动进行设置。 I know I can add custom style to all buttons like that: 我知道我可以像这样向所有按钮添加自定义样式:

button { ...some-properties... }

but I would need something like that: 但我需要这样的东西:

button { .btn }

I know I can achieve that with LESS, but my question is, if it is the only method to achieve that or is it possible using only CSS? 我知道我可以用LESS做到这一点,但是我的问题是,这是否是实现此目标的唯一方法,还是可以仅使用CSS? I have also found that I can achieve that using jQuery. 我还发现我可以使用jQuery实现这一目标。 For what it's worth, I am using AngularJS, maybe AngularUI or AngularStrap would help? 对于它的价值,我正在使用AngularJS,也许AngularUI或AngularStrap会有所帮助?

No, there's no such thing as extending a css class in pure css. 不,没有在纯CSS中扩展CSS类的事情。 The only way to achieve what you want would be to get the source css of bootstrap .btn class and add it to all buttons: 实现所需目标的唯一方法是获取bootstrap .btn类的源CSS,并将其添加到所有按钮:

button {
    // .btn source css
}

Even if it works, it's not a good approach since Bootstrap may change it in future versions. 即使可行,这也不是一个好方法,因为Bootstrap可能会在将来的版本中对其进行更改。 Css preprocessors like Less and Sass are probably the best way to do it. 诸如Less和Sass之类的Css预处理程序可能是最好的方法。

I don't think that there is another way except using Less in this scenario with CSS you cannot do this whatever you do because CSS is not CAPABLE of this LEVEL of Abstraction so Please Use LESS I assure you you cannot do this with CSS so don't waste Time a nd Use LESS like this: 我认为除了在CSS中使用Less之外,没有其他方法可以执行此操作,因为CSS无法满足此抽象级别的要求,因此请使用LESS,我保证您无法使用CSS进行此操作,所以不要不会浪费时间,而像这样使用LESS:

button { .btn; 按钮{.btn; } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM