Write CSS that is easy to read and everyone can understand
One of the struggles developers encounters while writing CSS is the fact that...
For further actions, you may consider blocking this person and/or reporting abuse
I used to group my CSS in a similar way, but as more and more properties were introduced, I switched to alphabetic sorting, and have never looked back! By the way, the position example can use the new
inset
property, to set all 4 sides with a single value:@madsstoumann yess! inset is an awesome property, I saved that one to another post along with other properties that saves time and are awesome.
Alphabetic sorting for the win!
But, in the few cases where alphabetic sorting can't be done because the order is important... please comment the code!
I know that many write the structure in alphabetical order, in my case it is not like that.
My order is this:
display
width
height
font (family, size, weight, line-height, etc.)
text
Colour
background-color
padding
margin
aling
justify
transittion
transform
position
z-index
@virla01 The alphabetical order for me is so tough because I have to think what letter comes after and before to search untilI find some property with that letter. My dyslexia kicks in automatically hahaha.
Just out of curiosity.
The align and justify properties been far away from the display give tou some kind of struggle to fix a code? Seen that you read the display and have to go to the end of the structure?
Yes, everything that has to do with flex or grid I usually use it at the end to have it separated from the rest
text-aling goes where it says text
simple and excellent
z-index: 999 is bad practice in almost all cases
I completely agreed, to be honest in those examples I put the first number that popped up on my mind. I should put a disclaimer about that, thank you for the feedback @vladi160
Awesome, very clean and clear,
I will try to apply this into my work,
Thanks
I wish I had read this years ago when I started writing css π
I have been playing around with a few
stylelint
rules/plugins for this, but haven't found the 'one',Suggestions welcome
Maybe github.com/ream88/stylelint-config... ? I didn't test it but it seems to do the job.