Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Naming convetion for nested elements #81

Open
Antoder10 opened this issue Jun 3, 2019 · 1 comment
Open

Naming convetion for nested elements #81

Antoder10 opened this issue Jun 3, 2019 · 1 comment

Comments

@Antoder10
Copy link

Hi! I'm new to BEM, trying to implement with a little project to learn it.

Inside my HTML file i have this code

<main class="game">

    <!-- Choose to play the game or see the highscores -->
    <div class="game__choose">
      <button class="btn" onclick="startGame()">Play Game</button>
      <button class="btn" onclick="showHighscores()">Show Highscores</button>
    </div>
    <!-- Choose to play the game or see the highscores -->

    <!-- Display elements of the game -->
    <div class="game__game-area">

      <div class="game__hud">
          <div id="questions-counter ">
              <h4>Question</h4>
              <h1>0</h1>
            </div>
            <div id="score">
              <h4 >Score</h4>
              <h1>0</h1>
            </div>
      </div>

    </div>
    <!-- Display elements of the game -->

According to the FAQs code should look like this

<div class='block'>
    <div class='block__elem1'>
        <div class='block__elem2'>
            <div class='block__elem3'></div>
        </div>
    </div>
</div>

So, my questions are:

  1. Is the class game__choose ok?
  2. In the class game__hud i have two more divs. Should the name be game__hud-question-counter or hud__question-counter for example?
@beinoriusju
Copy link

Hello, I'm also new to BEM.

Try to understand why and when to use mixes: https://en.bem.info/methodology/key-concepts/#mix

Without understanding mixes you can't further improve.

To comment on your "game" block..

  1. game__choose is OK
  2. game__game-area can and should be improved!

There are many ways, but my suggestion is to create new game-area block with it's own elements and use game__game-area for relative positioning/contextual stuff only.

<div class="game__game-area game-area">

	<div class="game-area__hud">
	  <div id="game-area__counter">
	      <h4>Question</h4>
	      <h1>0</h1>
	    </div>
	    <div id="game-area__score">
	      <h4 >Score</h4>
	      <h1>0</h1>
	    </div>
	</div>

</div>

As far as my knowledge goes you can break rules and create your own as long as you understand why the rules were created in the first place.

p.s. I would also avoid using multiple H1 tags on the same page (see here https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Heading_Elements). If you need to size text differently consider using SPANS or DIVS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants