我可以让这个CSS更简单,以避免重复的父选择器? [英] Can I make this CSS simpler to avoid repeating the parent selector?
本文介绍了我可以让这个CSS更简单,以避免重复的父选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到的常见模式如下:
A common pattern I come across is the following:
form.request input {
/* ... */
}
form.request input[type="text"] {
/* ... */
}
form.request select {
/* ... */
}
form.request br {
/* ... */
}
我有几行以相同的选择器开头( form.request
),我想选择各种孩子。我可以用更简洁的方式做到这一点没有重复(最好没有像LESS这样的附加依赖)?
I have several lines beginning with the same selector (form.request
), and I want to select various children. Can I do this in a neater way without the repetition (and preferably without additional dependencies like LESS)?
相关问题 - 如果所有上述注释都包含相同的样式,我做得比:
Related question - if all the above comments contain the same styles, can I do better than:
form.request input, form.request input[type="text"], form.request select, form.request br {
/* ... */
}
推荐答案
不,你不能。但是,如果您希望减少输入内容并使样式表更易于阅读,请考虑使用 SCSS 。
No, you cannot. But if you want to do less typing and make the stylesheets more readable, consider using SCSS.
这篇关于我可以让这个CSS更简单,以避免重复的父选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文