F
F
Finn the Boy2018-03-07 10:40:45
css
Finn the Boy, 2018-03-07 10:40:45

CSS: what about the grid?

The question is: should the grid styles be written as individual component styles (like the grid in bootstrap, for example) or is it better to write styles separately for each component?
Example: there is a header that consists of three sections: brand, navigation, actions.
If we write separate styles for the grid, the layout might look like this:

<header class="header">
    <div class="container">
        <div class="row">
            <div class="header__brand col-2">
                <a href="#">Brand</a>
            </div>
            <div class="header__menu col-8">
                <ul>
                    <li><a href="#">Item</a></li>
                </ul>
            </div>
            <div class="header__actions col-2">
            </div>
        </div>
    </div>
</header>

If we write styles for each component separately, the layout will be like this:
<header class="header">
    <div class="header__container">
        <div class="header__brand">
            <a href="#">Brand</a>
        </div>
        <div class="header__menu">
            <ul>
                <li><a href="#">Item</a></li>
            </ul>
        </div>
        <div class="header__actions">
        </div>
    </div>
</header>

Those. we will get rid of classes like container, row, col. However, it is possible that more styles will appear in CSS that are responsible for the positioning of elements.
Which of these options is better?
PS: I use flexbox to create the grid. Needs support for more browsers than with Grid.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima, 2018-03-07
Dolgoter @DDolgy

you hit?) why do you need to write the same css code for different classes + a lot of time

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question