0

I have the following SASS code.

How would I do the exact same but using the BEM methodolgy?

nav.primary ul {
    border-top: 2px solid $darkgreen;
    display:block;
    margin:10px 0 0 0;
    padding: 25px 0 0 0;

    li {
        background-color:#004f5a;
        display: inline-block;
        float: none;
        margin-left:0;
        padding: 5px 0;
        text-align: center;
        width: 100%;

        a {
        color:#fff;
        letter-spacing: 0.5px;

            &:hover {
                color:$darkgreen;
            }
        }
    }
}
Arpit Goyal
  • 1,017
  • 12
  • 25
michaelmcgurk
  • 6,367
  • 23
  • 94
  • 190

2 Answers2

2

For example, make a block .primary-nav with three elements .primary-nav__ul, .primary-nav__li, .primary-nav__a.

.primary-nav {
    &__ul {
        border-top: 2px solid $darkgreen;
        display: block;
        margin:10px 0 0 0;
        padding: 25px 0 0 0;
    }
    &__li {
        background-color: #004f5a;
        display: inline-block;
        float: none;
        margin-left: 0;
        padding: 5px 0;
        text-align: center;
        width: 100%;
    }
    &__a {
        color:#fff;
        letter-spacing: 0.5px;
        &:hover {
            color: $darkgreen;
        }
    }
}
Paleo
  • 21,831
  • 4
  • 65
  • 76
  • How would it work for multiple tier hierarchy? i.e. Many nested subnav within subnav. – Awin Oct 25 '17 at 07:54
1

BEM is a naming convention for classes (distinguishing identifiers and modifiers); the concept is to create ,very strict, single class selector.

The way this is achieved is through SCSS ampersand selector;

In your scenario , since you're markup doesn't combine classes to customize elements, it doesn't make much sense.

maioman
  • 18,154
  • 4
  • 36
  • 42