What are some tips for writing good CSS?

I just started doing web development a few months ago. I know HTML and I know how page layout should be semantically correct (without using tables for layouts, using new semantic elements from HTML5 correctly, etc.). I try to stick to the W3C design guidelines. However, it's hard for me to write “good” CSS.

I know about using efficient selectors like a child selector, not a descendant selector, etc. My problem is that I feel that my CSS does not match my markup semantics. It is assumed that CSS can be reused, which means that the same class can be used for multiple elements on multiple pages. But the CSS classes that I write apply only to a few elements (often only on one page) and are never used again. I often write the same styles, but with minor modifications, for many classes. This is contrary to the principle of DRY development.

Am I not using CSS in full? What are some ways to make my styles reusable without doing things like .right-align { } .blue-text { }?

+3
source share
3

- CSS. , , , .

+3

CSS, , ( ) . , , . DRY .

DRY , . , , .

, , :

  • , . , ( , , HTML) . , Id log-in-panel.

  • (, , , , , IE), . , Id .box1. , ( IE 6 Ive freelanced at), Id box.

If you have several classes that use similar styles, this is not necessarily a problem. CSS is usually pretty simple. DRY is useful when bug fixes and bug fixes for a piece of code should not be performed in more than one place. If re-CSS is not so complex, then there is no need to worry.

0
source

Source: https://habr.com/ru/post/1757264/


All Articles