Skip to content

Commit 55a0f75

Browse files
Merge pull request #12342 from nextcloud/feat/css-bem
feat(developer): Add BEM to CSS documentation
2 parents 6cbabd4 + f0edb0c commit 55a0f75

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

developer_manual/getting_started/codingguidelines.rst

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,10 @@ Control structures
449449
CSS
450450
---
451451

452-
Take a look at the `Writing Tactical CSS & HTML <https://www.youtube.com/watch?v=hou2wJCh3XE&feature=plcp>`_ video on YouTube.
453-
454-
Don't bind your CSS too much to your HTML structure and try to avoid IDs. Also try to make your CSS reusable by grouping common attributes into classes.
452+
- Do not bind your CSS to much to your HTML structure.
453+
- Try to avoid IDs.
454+
- Try to make your CSS reusable by grouping common attributes into classes.
455+
- Take a look at the `Writing Tactical CSS & HTML <https://www.youtube.com/watch?v=hou2wJCh3XE&feature=plcp>`_ video on YouTube.
455456

456457
**DO**:
457458

@@ -461,7 +462,7 @@ Don't bind your CSS too much to your HTML structure and try to avoid IDs. Also t
461462
list-style-type: none;
462463
}
463464
464-
.list > .list_item {
465+
.list > .list__item {
465466
display: inline-block;
466467
}
467468
@@ -482,4 +483,39 @@ Don't bind your CSS too much to your HTML structure and try to avoid IDs. Also t
482483
display: inline-block;
483484
}
484485
485-
**TBD**
486+
Naming convention
487+
^^^^^^^^^^^^^^^^^
488+
489+
We recommend to use the BEM (Block-Element-Modifier) naming convention for CSS classes.
490+
BEM helps with making CSS reusable and better maintainable, especially when using pre-processors like SASS.
491+
492+
**DO**:
493+
494+
.. code-block:: css
495+
496+
.button {
497+
background-color: var(--color-main-background);
498+
}
499+
500+
.button--primary {
501+
background-color: var(--color-primary);
502+
}
503+
504+
.button__icon {
505+
width: 20px;
506+
}
507+
508+
**DON'T**:
509+
510+
.. code-block:: css
511+
512+
button.btn {
513+
background-color: var(--color-main-background);
514+
}
515+
516+
button.btn.primary {
517+
background-color: var(--color-primary);
518+
}
519+
button.btn span.myIcon {
520+
width: 20px;
521+
}

0 commit comments

Comments
 (0)