TechQA.

Correct way to write according to BEM methodology for following markup?

49 views Asked by dkjain At 2016-09-11T14:37:44+00:00 11 September 2016 at 14:37 2025-12-08T11:31:50+00:00

Which is the correct way to write per BEM methodology for the following markup:

HTML:

<div class="col-sm-12 header">
    <div class="logo">
        <img class="logo__img" src="images/logo.png" />
    </div>
</div>

CSS:

header {}
logo{}
logo__img{}

Or:

HTML:

<div class="col-sm-12 header">
    <div class="header__logo">
        <img class="logo__img" src="images/logo.png" />
    </div>
</div>

CSS:

header {}
header__logo{}
logo__img{}
bem smacss
Original Q&A
1

There are 1 answers

0
3rdthemagical 3rdthemagical On 2016-09-20T13:10:56+00:00 20 September 2016 at 13:10

You have two blocks: header and logo. Logo has an element - image. Basic structure is:

header {}
logo {}
logo__image {}

At first you should decide is wrapping div is really needed? Maybe you can just write:

<img class="logo" src="images/logo.png" />

Anyway.
If logo in header has some custom styles, for example margins or different sizes, you should add modificator logo_modificator to customise logo in header.

logo {}
logo_modificator {}
logo__image {}
logo_modificator logo__image {}

What's more I recommend you to separate col and header.

<div class="col-sm-12">
    <div class="header">
        <div class="logo">
            <img class="logo__img" src="images/logo.png" />
        </div>
    </div>
</div>

Related Questions in BEM

  • How to set case of BEM in VSCode?
  • Using BEM for large set design
  • How do I use BEM in a component structure?
  • BEM configuration for react typescript
  • How to categorize typography variants in BEM?
  • Multiple classes on same parent element not working at the same time: BEM
  • How to style buttons using BEM?
  • I need help, my first time using BEM, is this correct?
  • Multiple BEM elements and modifiers in Sass
  • Is there any way to style a <svg> fill property inside a <p> tag using just one modifier without violating the BEM CSS principles?
  • what is service block in BEM naming methodology?
  • Should I create a block or an element BEM CSS?
  • Reactjs, Bem naming nested structure with SCSSModule
  • Can a BEM Block have optional Elements?
  • Double underscore '__' in BEM of NextJS Css module throw error

Related Questions in SMACSS

  • ERRNO::ENOENT: No such file or directory @rb_sysopen - sass/app.sass
  • SMACSS\BEM - how to correctly handle icon style?
  • SMACSS how to identify what to put in modules?
  • What is the difference between vanilla css and modular css
  • How to structure all project styles by smacss methodology?
  • How to reference multiple sub-classes on the same element with SASS
  • Correct way to write according to BEM methodology for following markup?
  • Where to put grid layout in SUSY/SMACSS structure
  • SMACSS defining colours for modules
  • Are SMACSS, BEM and OOCSS not as portable?
  • How to name nested elements using BEM and SMACCS
  • using smacss is it recommended that modules never set margins but let this be handled by layout/containers?
  • OOCSS/modular CSS: Fighting link styles, how to resolve?
  • Folder structure of a SMACSS project – Where to put class?
  • How do you handle layout specific changes to modules in SMACSS?

Popular Questions

  • How do I undo the most recent local commits in Git?
  • How can I remove a specific item from an array in JavaScript?
  • How do I delete a Git branch locally and remotely?
  • Find all files containing a specific text (string) on Linux?
  • How do I revert a Git repository to a previous commit?
  • How do I create an HTML button that acts like a link?
  • How do I check out a remote Git branch?
  • How do I force "git pull" to overwrite local files?
  • How do I list all files of a directory?
  • How to check whether a string contains a substring in JavaScript?
  • How do I redirect to another webpage?
  • How can I iterate over rows in a Pandas DataFrame?
  • How do I convert a String to an int in Java?
  • Does Python have a string 'contains' substring method?
  • How do I check if a string contains a specific word?

Popular Tags

javascript python java c# php android html jquery c++ css ios sql mysql r reactjs node.js arrays c asp.net json

Trending Questions

  • UIImageView Frame Doesn't Reflect Constraints
  • Is it possible to use adb commands to click on a view by finding its ID?
  • How to create a new web character symbol recognizable by html/javascript?
  • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
  • Heap Gives Page Fault
  • Connect ffmpeg to Visual Studio 2008
  • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
  • How to avoid default initialization of objects in std::vector?
  • second argument of the command line arguments in a format other than char** argv or char* argv[]
  • How to improve efficiency of algorithm which generates next lexicographic permutation?
  • Navigating to the another actvity app getting crash in android
  • How to read the particular message format in android and store in sqlite database?
  • Resetting inventory status after order is cancelled
  • Efficiently compute powers of X in SSE/AVX
  • Insert into an external database using ajax and php : POST 500 (Internal Server Error)
  • Privacy
  • Terms
  • Cookies
  • Homegardensmart
  • Math
  • Aftereffectstemplates