The 3 Short December CSS tips

Hey folks!

I’d like to talk about why you should define what you need to define, the poor habit to define display: block for pseudo-elements ::before and ::after, what to better between align-items: center and margin: auto.

But before embarking on re…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Stas Melnikov

Hey folks!

I’d like to talk about why you should define what you need to define, the poor habit to define display: block for pseudo-elements ::before and ::after, what to better between align-items: center and margin: auto.

But before embarking on reading I leave the link on my Substack newsletter about CSS. If you wanna read more tips you know what to make 😎

Also, thank you so much, my sponsors: Ben Rinehart, Tatiana Ten, Konstantinos Kapenekakis. I didn’t write this article without their support.

Define only what you need to define

Code#1 defines background: tomato via the .example selector. So we have 9 implicitly defined background properties. Code#2 defines the same but with background-color: tomato without defining implicitly properties

There’s the perfect trick to write scalable CSS that won’t make you suffer. Don’t define what is unnecessary. If you need to define a background color make it with background-color and not with background 💡

display: grid gets rid of the habit of defining display: block

Code#1 defines display: block for the ::before pseudo-element via the .parent::before selector when display: grid is defined to the parent via the .parent selector. Code#2 defines the same but without defining display: block for the ::before pseudo-element because browsers make it themselves

Are you used to defining display: block for ::before or ::after? Folks, there is no need to make it if you define display: grid or display: inline-grid to the parent. Browsers make it themselves🙂

align-items: center or margin: auto. What’s better?

Code#1 demonstrates using align-items: center. As a result the top part of the dialog might be hidden if the user display height will be less than the element height

Code#2 demonstrates using margin: auto. As a result the top part of the dialog won't be hidden
Warning! Using justify-content or align-items might lead to losing data. It’s why I can’t close a dialog. margin: auto is the best alternative😉


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Stas Melnikov


Print Share Comment Cite Upload Translate Updates
APA

Stas Melnikov | Sciencx (2022-12-26T17:30:02+00:00) The 3 Short December CSS tips. Retrieved from https://www.scien.cx/2022/12/26/the-3-short-december-css-tips/

MLA
" » The 3 Short December CSS tips." Stas Melnikov | Sciencx - Monday December 26, 2022, https://www.scien.cx/2022/12/26/the-3-short-december-css-tips/
HARVARD
Stas Melnikov | Sciencx Monday December 26, 2022 » The 3 Short December CSS tips., viewed ,<https://www.scien.cx/2022/12/26/the-3-short-december-css-tips/>
VANCOUVER
Stas Melnikov | Sciencx - » The 3 Short December CSS tips. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/12/26/the-3-short-december-css-tips/
CHICAGO
" » The 3 Short December CSS tips." Stas Melnikov | Sciencx - Accessed . https://www.scien.cx/2022/12/26/the-3-short-december-css-tips/
IEEE
" » The 3 Short December CSS tips." Stas Melnikov | Sciencx [Online]. Available: https://www.scien.cx/2022/12/26/the-3-short-december-css-tips/. [Accessed: ]
rf:citation
» The 3 Short December CSS tips | Stas Melnikov | Sciencx | https://www.scien.cx/2022/12/26/the-3-short-december-css-tips/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.