for example
<li class="list-item">
<h1 class="title list"></h1>
</li>
use .list-item. Title {}
or .title.list {}
for example
<li class="list-item">
<h1 class="title list"></h1>
</li>
use .list-item. Title {}
or .title.list {}
first of all.
there is something wrong with your name.
generally there should be only one title, while a list represents a list, these two levels. What exactly is the structure of your html?
in fact, the hardest thing about css is naming, which determines its reuse and closeness. The choice of selectors is not a problem.
for example, you want to encapsulate list item
at this time you are very clear that a list must have item,Item in list
then it is
.list .item or even .list > .item
so as to maximize the guarantee that your style will not be confused.
as for performance, I think you can forget about it. First consider reusability, write too much naturally know how to choose, naturally know where good and bad.
as for how to maintain high reusability, in fact, my own suggestion is to use scss as a preprocessor to write, and then adhere to a principle. In the past, the page source code structure was usually
page
.js
.html
.css/.scss
now becomes
page
.js
.html
style
.css
this structure to write. I think it is mandatory to improve reusability. When you are writing js, maybe you are writing business, but when you are writing css, you should realize that you are writing a framework (of course, if you want vue, you should consider how not to write css without introducing a style framework and all reuse is solved by components)
I am still learning, and I hope to give you some help
1. If your title class and list class may be reused, that is, other elements may also use these two classes, it must be written separately
2. If you just want to define the style of list, then one class is enough
Previous: The question of oplog update
Next: What if a vue-cli project contains both mobile-side pages and PC-side pages?