Nice article! Don't forget the beauty of default values for a css variable.
background-color: var(--background-color, midnightblue)
with this you'll make it possible te have a default but override it if you want to.
I also use css variables in combination with calc() sometimes
margin: 20px calc(20px - var(--some-special-width-var, 0px))
in your last example you need to use 0px instead of 0 because the unitless value will make the calc() invalid because calc(20px - 0) is invalid (more detail : stackoverflow.com/a/55406181/8620333)
0px
0
calc(20px - 0)
Thnx! Changed it. So easy to forget the details..
Thank you! You make a very good point- always good practice to have a default value.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Nice article!
Don't forget the beauty of default values for a css variable.
background-color: var(--background-color, midnightblue)
with this you'll make it possible te have a default but override it if you want to.
I also use css variables in combination with calc() sometimes
margin: 20px calc(20px - var(--some-special-width-var, 0px))
in your last example you need to use
0px
instead of0
because the unitless value will make the calc() invalid becausecalc(20px - 0)
is invalid (more detail : stackoverflow.com/a/55406181/8620333)Thnx! Changed it. So easy to forget the details..
Thank you! You make a very good point- always good practice to have a default value.