Skip to content Skip to sidebar Skip to footer

Bem And Layout Rich Texts

I read here that it is a good BEM practise to use layout components to arrange the flow and positioning of other components. The resource suggests the following example:

Solution 1:

BEM is a good tool to layout a website, it is also an excellent tool to structure the appearance of a web application. But, use BEM to style rich texts? It's just... not the good tool.

I suggest you to create a "not BEM component", named rich-text, with cascades:

.rich-textp {
  /* style here, including margins and paddings */
}
.rich-texthr {
  /* style here, including margins and paddings */
}
.rich-textul {
  /* style here, including margins and paddings */
}
.rich-textul > li {
  /* style here, including margins and paddings */
}
// etc.

And in your HTML code:

    <section class="c-page-section c-page-section--white-bg">
       <divclass="l-container rich-text"><h1>Page Title</h1><hr><p> ... </p><p> ... </p><p> ... </p><ul><li>Java</li><li>PHP</li><li>HTML</li><li>CSS/SASS</li></ul></div></section>

Then, you have to remember that other BEM components cannot be nested into this rich-text component (because of cascades). But even with the BEM methodology you could not nest any component anywhere in a richtext. Due to the semantic limitation of tags <p> or <em> that cannot embed <div> for example.

Notice: I suggest to not style .rich-text itself as a block: no padding neither margin or background. It is more reusable if all properties of the rich text component are only about the rich text elements. You could need to display several rich texts in the page and they won't share the same background or paddings. If you need to display the rich text in a white rectangle with borders, just create a true BEM component for that and make it a container of the rich text.

Post a Comment for "Bem And Layout Rich Texts"