From dcfb172704f3afb68a30425029ec834be2883274 Mon Sep 17 00:00:00 2001 From: bt Date: Sat, 8 Jun 2024 13:22:19 -0400 Subject: More content porting, on-going markdown changes for lowdown support --- build/css-variables/index.html | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'build/css-variables') diff --git a/build/css-variables/index.html b/build/css-variables/index.html index eb7d568..b470633 100644 --- a/build/css-variables/index.html +++ b/build/css-variables/index.html @@ -1,32 +1,42 @@ - + CSS Variables - - + + +
-

CSS Variables

+

CSS Variables

+

2018-03-24

-

The CSS language is becoming even more awesome and powerful everyday. In this quick article I'd like to focus specifically on the "new" CSS variable function that you can start using in your projects right now.

-

Getting started is easy

-

Let's just jump right in - this is how you create variables in vanilla CSS:

+ +

The CSS language is becoming even more awesome and powerful everyday. In this quick article I’d like to focus specifically on the “new” CSS variable function that you can start using in your projects right now.

+ +

Getting started is easy

+ +

Let’s just jump right in - this is how you create variables in vanilla CSS:

+
:root {
     --base-color: #e0e0e0;
     --text-color: #111;
 }
 
+

We are using the :root selector at the very top of our CSS file in order to call these variables into any elements in the rest of our document. This is normally the safest way to include variables.

-

As for the variables themselves, you declare that they are variables using the -- tags, followed by the variable's name and it's property. Pretty simple stuff, right?

-

Now let's use those variables:

+ +

As for the variables themselves, you declare that they are variables using the -- tags, followed by the variable’s name and it’s property. Pretty simple stuff, right?

+ +

Now let’s use those variables:

+
.header {
     border: 1px solid var(--base-color);
 }
@@ -36,9 +46,13 @@
     color: var(--text-color);
 }
 
-

That's it! It's also good to know that CSS variables have pretty decent browser support (who likes IE11 anyway).

-

Why not just use a preprocessor?

-

I'm a pretty big fan of Sass and Stylus, but sometimes it's refreshing to just use vanilla CSS for certain projects. Most preprocessors have had the ability to use variables and mixins for a while, but I prefer to avoid build scripts when not absolutely necessary.

+ +

That’s it! It’s also good to know that CSS variables have pretty decent browser support (who likes IE11 anyway).

+ +

Why not just use a preprocessor?

+ +

I’m a pretty big fan of Sass and Stylus, but sometimes it’s refreshing to just use vanilla CSS for certain projects. Most preprocessors have had the ability to use variables and mixins for a while, but I prefer to avoid build scripts when not absolutely necessary.

+

Get out there and have fun with some variables!