What does BEM bring to the table alongside Bourbon Neat and semantic HTML5?

As I venture into the world of web development, I have decided to create a simplistic blog using HTML and CSS. The dilemma I face is whether to select elements on my page using plain tags, IDs, or classes.

For instance, here is a snippet of what one of my pages might look like:


    <body>
     <header>
      <h1><a href="/">My fabulous blog</a></h1>
      <nav>
       <ul>
        <li><a href="#">Page one</a></li>
        <li><a href="#">Page two</a></li>
       </ul>
      </nav>
     </header>

     <section>
        <h1>Latest articles</h1>
        <article>
          <h1>Title</h1>
          <p>I like turtles</p>
        </article>

        <article>
          <h1>Title</h1>
          <p>I like potatoes too</p>
        </article>

      <a href="#">Browse the archive.</a>
     </section>

     <aside>
       <h2>Social</h2>
       <ul>
         <li>Twitter</li>
         <li>Facebook</li>
         <li>Github</li>
       </ul>
       </aside>

    <footer>© 1546-2032</footer>
    </body>

This structure is very basic, with no classes or IDs used throughout.

The corresponding CSS would be:


    body {
      @include outer-container;
    }

    header {
      @include span-columns(12);
    }

    section
    {
      @include span-columns(9);
    }
    aside
    {
     @include span-columns(3);
    }

    footer{
      @include span-columns(12);
    }

    header, aside, footer
    {
      @include omega;
    }

I am considering the BEM methodology for structuring my CSS styles. How heavily should I rely on this approach? Should I start with tag selectors for layout and then implement BEM modifiers for styling, or go all in with BEM by using classes everywhere?


    <header class="main-header">
     <h1 class="main-header__title"><a href="/">My fabulous blog</a></h1>
     <nav class="main-header__nav">
      <ul class="main-header__links">
       <li class="main-header__item"><a href="#">Page one</a></li>
       <li class="main-header__item"><a href="#">Page two</a></li>
      </ul>
     </nav>
    </header>

SCSS example:


    main-header {
      &__title {
      ...
      }
      &__nav {
      ...
      }
      &__links {
      ...
      }
      &__items {
      ...
      }

    }

Alternatively,


    <body class="body">
    [...]
    <header class="header">
    [...]
    </header>
    <section class="last-articles">
        <h1 class="last-articles__title">Latest articles</h1>
        <article class="article">
          <h1 class="article__title">Title</h1>
          <p class="article__p">I like turtles</p>
          <p class="article__p">But I also like potatoes.</p>
          <p class="article__p"`;gt;But I don't like them both in the same dish.</p>
          <p class="article__p"> Except in soup.</p>

        </article>

SCSS:


    .body{
    @include outer-container;
    }
    .header
    {
    @include span-columns(12);
    }
    .last-articles
    {
      @include span-columns(9);
      &__title {

      }
    }
    .article
    {
      &__title{

      }
      &__p{

      }
    }

Ultimately, I aim to understand the best practices for utilizing Bourbon/Neat and BEM to optimize code readability, reusability, and performance.

Answer №1

Utilize class selectors exclusively for better code legibility.

Answer №2

One suggestion I have is to utilize classes for your styling preferences. By doing this, you establish a balanced playing field in terms of specificity and enhance the reusability and transferability of your styles.

While Bourbon and Neat serve as helpful tools for improving Sass writing efficiency, they should not dictate the architectural direction you take. Implementing BEM can aid in organizing classes and improving clarity for fellow developers. Semantic HTML focuses on the meaning of the content itself, but it's important not to sacrifice code clarity for semantics. It is advisable to accurately mark up content to make it machine-readable (e.g., using heading elements for titles, list elements for lists, header for headers), and apply classes to add style. These two aspects do not necessarily need to be interconnected.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

javascript/AngularJS - make elements gradually disappear

I need help implementing a fade effect for an icon in the middle of a picture that indicates scrollability to the user. Currently, when the user scrolls, I can hide the icon but would like to add a nice smooth fade-out effect. Here is the HTML code snippe ...

Unraveling and interpreting all incoming requests to my Node.js application

Looking for a simple method to identify and decipher all encoded characters in every URL received by my Node.js application? Is it possible to achieve this using a middleware that can retrieve and decode symbols such as & ? ...

Scroll downwards to reveal the hidden div element on an HTML page

How can we implement a Snapchat-inspired feature in a web application using AngularJS? The idea is to have a div appear when the user scrolls down or pulls the screen down, and then have it pushed back up when they scroll back up. This functionality is si ...

Ways to eliminate line breaks and <br> tags in text using only CSS to create a button that trunc

I am currently working on incorporating a truncated text button using only CSS. The issue I'm facing is that the "show more" button doesn't ignore the line breaks or any other relevant HTML within the teaser and text body. This is causing too muc ...

Breaking a line within an ngFor loop

I'm working with an ngFor loop to generate multiple PrimeNG buttons. Currently, the buttons are displayed side by side on the same row, but I want each button to appear vertically on its own line. How can this be achieved? Below is the segment of my c ...

Bootstrap-enhanced JavaScript table filter functionalities

Hello, I am facing an issue with the table filter functionality. It seems to be working fine, but when I search for a name like "John" and there are multiple instances of "John" in the table, there is some blank space between the tables. I suspect the prob ...

Issue with Javascript redirect not working following form submission in combination with Asp Classic

After countless hours of research and experimentation, I find myself at a standstill. My web page is coded extensively, so I'll do my best to provide a concise summary. The core elements of my ASP CLASSIC page for creating tickets via a form are as f ...

What are the steps to accomplish this using react.js?

I am looking to create a toggle box with three columns in a row similar to the image below. https://i.sstatic.net/vPhIe.png Here is an example of the dummy data: export const topicDummy: TopicData = [ { id: 1, name: 'Netflix&apos ...

What is the best way to ensure that an element remains active even after a page refresh?

I have been using this code to activate the current element, which I came across on a website called "w3schools.com". However, whenever I refresh the page, the currently active element disappears. Is there a way to ensure that the active element remains hi ...

Enhance the appearance of Bootstrap forms with custom styles

After customizing a selection form in Bootstrap to mimic a specific image, I have successfully added the necessary styles. If you wish to see the html and css used to achieve this design, please refer to the link below: https://i.sstatic.net/b67Yf.png HT ...

Swap out the svg element with an icon alternative

Transforming Circle Elements into Shopping Cart Icons I am attempting to change the appearance of my SVG circle elements to resemble shopping carts. Is there a method to completely alter the definition of a circle element in svg so that it displays a spec ...

Bootstrap alert JS refuses to slide down

Here is the JavaScript code to make a blue bar slide down on click: $('#comment').click(function(e) { e.preventDefault(); $('#comment').slideDown(); }); ...

Ways to loop through individual characters within a string

Is there a way to iterate through a string using the *ngFor? I have a string that contains binary code (e.g. 0010) and depending on each bit, I need to display a different icon. <div class="row" *ngFor="let item of subscribedCommandBus2Easy; let i = in ...

Ways to divide the vuetify-text-field-label into two lines

My vuetify text field has a label that is too long for mobile devices. I am wondering if there is a way to automatically wrap the text. I attempted using div and p, as shown in this codepen link <div id="app"> <v-app id="inspire ...

The PHP login functionality is malfunctioning due to issues with password verification

I am currently working on a project for my assignment and I seem to be facing an issue with the login functionality. The error message that keeps popping up says: Login error username does not exist. Interestingly, when I tested the customer login and r ...

The scrollbar in the InfoWindow of an Angular GoogleMaps marker is not being hidden

Is it possible to customize the popup info window that appears when a marker is clicked, without having a scrollbar on the right if the content overflows? Visit this link for an image (image didn't load when using the image template) I've attem ...

"Seeking assistance with concept sharing and content transmission. In need of guidance

Basic Question I'm stuck trying to brainstorm a concept to reach my objective. I am having trouble figuring out how to navigate the DOM correctly with my chosen method. The Objective First, let me explain what I am doing: I use ajax to bring HTML ...

Tips on adding CSS to a React component

I've successfully converted an HTML file into a component designed to resemble a 7-segment LED display. I have imported the necessary CSS styles from the index.css file, but I am unsure how to properly apply these styles within the component. My atte ...

Is there a way to apply a margin-top solely to the image section within the span?

I have a span that has a sparkling effect with an image before the text, but for some reason the image is aligned to the top. However, if I remove the image part and just use dots before it, it displays correctly. Current Display: Expected Outcome: CSS: ...

Is it possible to display only the top level elements of a nested collection in Jekyll?

When using Jekyll Liquid templates, is there a way to render items from a collection at the top of a hierarchy using a for loop? proj_folder - _items • item_1.md • item_2.md - subfolder_1 • item_1-1.md • item_1-2.md - ...