There is a common scenario that keeps coming up when I'm designing blocks with complex layouts, which is the need for what I would call "wrapper elements" (and I mean BEM elements). I'd appreciate any help:
Look at the above picture. This is a "course-card" block. Among its elements, there are these two:
.course-card__duration
.course-card__level
Pretty straight-forward so far. Now, in order to achieve the layout that you see there, I would need another element to wrap those two, and its CSS would look something like this:
.course-card__? {
display: flex;
justify-content: space-between;
}
Now, the question is, what should such an element be called according to BEM standards?! It's an element that doesn't serve any semantic purpose, it's just there for layout purposes. I could think of the following options:
- course-card__level-and-duration-wrapper (which obviously looks horrible!)
- course-card__basic-info (still not ideal)
- you tell me?
This is not a rare case. I encounter one of these "wrapper element" cases in almost every block I'm implementing. In this same block, you can see in the picture that there is a need for another wrapper element that wraps instructor-avatar and instructor-name. I also couldn't find a satisfactory answer to this question, neither in en.bem.info nor in Stack Overflow or anywhere else, really.
- Should we add a "wrapper" or "container" suffix to the names of these kinds of elements?
- Should their names be as semantic as possible? For instance "basic-info" in the first example, and "instructor-info" in the second example? And we should avoid words like "wrapper" and "container" as much as possible?
- Are there any other guidelines and conventions in general to deal with these kinds of situations?
So, I'd appreciate any guidance. Thanks in advance.
First of all, that’s very good question — thank you!
I’d like to say that there is no any strict guidelines on methodology level. But according to our experience I would recommend following priority order of decisions:
basic-info
) — really often it’s possible and, even if it will be slightly far-fetched, those “normal” uniq names will help you talk about different elements such this better than ugly uniform names/
col if we do some tables, so if your block have clear sections in their skeleton there is no problem to have elements suchsubsection
/mainsection
You already describe good understanding of problem so my answer only add 2nd option and suggest priority axis.
@veged Thanks a lot, Sergey, I appreciate your answer.