<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Elenwo Gift Broma</title>
    <description>The latest articles on DEV Community by Elenwo Gift Broma (@bromagift).</description>
    <link>https://dev.to/bromagift</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F244637%2F03925689-d129-4280-bffe-db7e684100d9.jpeg</url>
      <title>DEV Community: Elenwo Gift Broma</title>
      <link>https://dev.to/bromagift</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bromagift"/>
    <language>en</language>
    <item>
      <title>Introduction to BEM</title>
      <dc:creator>Elenwo Gift Broma</dc:creator>
      <pubDate>Mon, 12 Oct 2020 08:59:38 +0000</pubDate>
      <link>https://dev.to/bromagift/introduction-to-bem-4gh9</link>
      <guid>https://dev.to/bromagift/introduction-to-bem-4gh9</guid>
      <description>&lt;p&gt;Naming classes in CSS has always been difficult for me😥. Luckily a few months ago I came across the BEM naming convention. A naming convention is an agreed style for naming things(in this case CSS). There are different CSS naming conventions available, such as SMACSS, AMCSS, BEM, etc. For this article, however, I would be talking about BEM.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Basic knowledge of Html and CSS.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is BEM
&lt;/h2&gt;

&lt;p&gt;BEM is short for Block Element Modifiers and is a CSS naming convention for classes in HTML and CSS.&lt;br&gt;
The Block refers to a component such as a header, footer, nav, button, inputs, and the likes.&lt;br&gt;
Element - they are found inside the block(components). they may be seen as children of the overall parent component.&lt;br&gt;
Modifiers on the other hand are used to style a block or an element without affecting other unrelated components&lt;/p&gt;
&lt;h2&gt;
  
  
  Why use BEM
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;BEM helps us write CSS that is easy to read and maintain.&lt;/li&gt;
&lt;li&gt;In large projects, BEM ensures that there are no conflicting styles.&lt;/li&gt;
&lt;li&gt;It conveys the function and purpose of a CSS code.&lt;/li&gt;
&lt;li&gt;It helps developers better understand the relationship between the HTML and CSS in a given project.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  How to use BEM
&lt;/h2&gt;

&lt;p&gt;Now that we know what BEM is and why we should use it, its time to dive into the how. The parent components are named by using a single hyphen as seen in the example below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;section class="about-us"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Element class names on the other hand are derived by adding two underscores (__), followed by the element name, like so&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h3 class="about-us__title"&amp;gt;best title &amp;lt;/h3&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;p class="about-us__text"&amp;gt;I love bunnies&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;when naming modifiers, we use two hyphens (--) followed by the name of the element&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;span class="about-us__title--green"&amp;gt;ever&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Putting it all together we have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;section class="about-us"&amp;gt;
     &amp;lt;h3 class="about-us__title"&amp;gt;best title
        &amp;lt;span class="about-us__title--green"&amp;gt;ever&amp;lt;/span&amp;gt;
     &amp;lt;/h3&amp;gt;
     &amp;lt;p class="about-us__text"&amp;gt;I love bunnies&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;we could style it like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.about-us{
    margin: 0 auto;
    color: #fff;
}
.about-us__title {
   font-weight: bold;
}
.about-us__title--green {
   color: #05b993;
}
.about-us__text {
    font-size: 24px;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Scss makes it even easier for us to style BEM. Styling this with SCSS would look like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.about-us{
  margin: 0 auto;
  color: #fff;
  &amp;amp;__title {
    font-weight: bold;
    &amp;amp;--green {
      color: #05b993;
    }
  }
  &amp;amp;__text {
    font-size: 24px;
   }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Pretty cool right?&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Truly, BEM gives our CSS a solid structure that is easier to understand. You may not get it right now, but I'm sure with time you will. Have fun naming with BEM.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
