Cookie Consent by Free Privacy Policy Generator ๐Ÿ“Œ CSS Variables and why i use them

๐Ÿ  Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeitrรคge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden รœberblick รผber die wichtigsten Aspekte der IT-Sicherheit in einer sich stรคndig verรคndernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch รผbersetzen, erst Englisch auswรคhlen dann wieder Deutsch!

Google Android Playstore Download Button fรผr Team IT Security



๐Ÿ“š CSS Variables and why i use them


๐Ÿ’ก Newskategorie: Programmierung
๐Ÿ”— Quelle: dev.to

What are they?

Like in most programming languages, CSS variables are used to store a value or property. You would mostly make them root scoped, meaning you make a :root psuedo class and make the variables in them. To make the variables you type -- followed by the name, then you type what the value is. As an example we can make a variable that stores the color black by typing --black: #0000 in the root. You use them by typing var() css function and type their full name in it, for example if we wanted to set a text's color to black we would type color: var(--black). You can also upadate the value of the variable locally, meaning you can change them in different selectors.

Helps find colors

A common way web developers use css variables is to store colors. Say that your making a big website with lots of different hex colors. It would take a long time just to re-type the hex colors you used onto multiple selectors, plus it'll be harder to show others the colors your using (like in a code snippet). With CSS variables we can store all of our hex, rgb, or hsl colors and name them the specefic color that they are. Here's an example:

Can you quickly know the background color of the body?

body {
background-color: #06D6A0;
}

How about now?

:root {
--Emerald-green: #06D6A0;
}

body {
background-color: var(--Emerald-green);
}

This shows that with CSS variables people can better understand the specefic colors your using, and it'll be easier for the web developer to type in the color they want instead of having to memorize the hex color.

Shortening image links

If you've ever imported an image from the internet and used it for the backgroud image of something you'll know that the URL is pretty long taking up lines of your css. I deal with this by making an external css file where i store all my images and svg's in variables. I then import that file into my main css file and call the variables to be the background images for my div's. I've been using this method for a week now, and i think its useful for when your blogging and using code snippets or when you have really big projects with lots of images, so the css in the main file will be shorter and easier to understand. It's of a way to clean your code then to lower your bundle size. Here's an example:

Could you tell me the background image of the body?

body {
background-image: url('https://images.unsplash.com/photo-1606567595334-d39972c85dbe?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=387&q=80');
}

How about now?

@import "images.css";

/*Say that we stored a picture of a bird
in a variable on images.css*/

body {
background-image: var(--bird);
}

As you can see CSS variables shorten our main code by a high amount, and since we imported the css from our image css file we got all of its variables as well.



There are lots of other ways people use css variables, these are just the ways i use them as a junior web dev, so you can try these methods yourself on your own projet! I hope this blog helped you, so have a good day/night ๐Ÿ‘‹. ...



๐Ÿ“Œ CSS Variables and why i use them


๐Ÿ“ˆ 46.1 Punkte

๐Ÿ“Œ Theming using CSS Variables? Turn Them into VS Code Snippets for Faster, Error-Free Coding


๐Ÿ“ˆ 34.1 Punkte

๐Ÿ“Œ Custom Properties vs. CSS Variables: Understanding the Differences and When to Use Each


๐Ÿ“ˆ 31.6 Punkte

๐Ÿ“Œ Refactoring instance variables to local variables in Rails controllers


๐Ÿ“ˆ 31.52 Punkte

๐Ÿ“Œ How to declare Boolean variables in bash and use them in a shell script


๐Ÿ“ˆ 31.04 Punkte

๐Ÿ“Œ CSS Grid: Moving From CSS Frameworks To CSS Grid (2018 and beyond)


๐Ÿ“ˆ 30.12 Punkte

๐Ÿ“Œ A BRIEF REVIEW OF CSS CASCADING, CSS SELECTORS and CSS SPECIFICITY.


๐Ÿ“ˆ 30.12 Punkte

๐Ÿ“Œ How to use CSS variables to create amazing theme transitions ๐ŸŽจโœจ


๐Ÿ“ˆ 29.82 Punkte

๐Ÿ“Œ How to use variables in CSS


๐Ÿ“ˆ 29.82 Punkte

๐Ÿ“Œ [How to] use CSS Variables in React Component


๐Ÿ“ˆ 29.82 Punkte

๐Ÿ“Œ Stylify CSS: Automagic CSS bundles splitting into CSS layers in Astro.build


๐Ÿ“ˆ 28.34 Punkte

๐Ÿ“Œ Choosing the Right CSS Approach: Tailwind CSS vs Bootstrap vs Vanillaย CSS


๐Ÿ“ˆ 28.34 Punkte

๐Ÿ“Œ Static Variables in Java โ€“ Why and How to Use Static Methods


๐Ÿ“ˆ 27.77 Punkte

๐Ÿ“Œ CSS Variables Scoping to Create and Theme Flexible UI Components


๐Ÿ“ˆ 26.99 Punkte

๐Ÿ“Œ Create Dark and Light Modes via CSS Variables for Astro.js sites


๐Ÿ“ˆ 26.99 Punkte

๐Ÿ“Œ Implementing Very Basic Dark/Light Modes with CSS Variables and JavaScript ๐ŸŒ“


๐Ÿ“ˆ 26.99 Punkte

๐Ÿ“Œ Clean Architecture: Theming with Tailwind and CSS Variables


๐Ÿ“ˆ 26.99 Punkte

๐Ÿ“Œ Optimize your workflow with Tailwind CSS: Get class completions and hover previews for classes assigned to variables in VScode


๐Ÿ“ˆ 26.99 Punkte

๐Ÿ“Œ Why Tailwind CSS is still better than StyleX and other CSS libraries


๐Ÿ“ˆ 26.29 Punkte

๐Ÿ“Œ CSS Variables end to end


๐Ÿ“ˆ 25.21 Punkte

๐Ÿ“Œ Angular Styling Made Easy: Leveraging the Power of CSS Variables


๐Ÿ“ˆ 25.21 Punkte

๐Ÿ“Œ Exploring Variables in CSS (custom properties)


๐Ÿ“ˆ 25.21 Punkte

๐Ÿ“Œ "--variables " in CSS ๐Ÿคฏ THE COMPLETE GUIDE โšก


๐Ÿ“ˆ 25.21 Punkte

๐Ÿ“Œ Advanced CSS Selectors โ€“ How and When to Use Them


๐Ÿ“ˆ 24.72 Punkte

๐Ÿ“Œ Node.js Environment Variables: How to Set Them Properly


๐Ÿ“ˆ 24.65 Punkte

๐Ÿ“Œ Why do I distrust CSS Frameworks (and why should you, sometimes)?


๐Ÿ“ˆ 22.45 Punkte

๐Ÿ“Œ testing Sophos AV detects wannacry. I use USB flash drives from Windows boxes, might as well clean them when I plug them in my Linux box!


๐Ÿ“ˆ 22.39 Punkte

๐Ÿ“Œ How to Set and Use Environment Variables In Bash Script


๐Ÿ“ˆ 22.15 Punkte

๐Ÿ“Œ Simplify the Use of ENV Variables in Percona Monitoring and Management AMI


๐Ÿ“ˆ 22.15 Punkte

๐Ÿ“Œ Why are div buttons bad for accessibility, and why should we stop using them?


๐Ÿ“ˆ 21.89 Punkte

๐Ÿ“Œ My next PC webcam NEEDS Microsoft's answer to Face ID โ€” Here's why (and why we need more companies to make them)


๐Ÿ“ˆ 21.89 Punkte

๐Ÿ“Œ How and Why to Use โ€œdisplay: table-cellโ€ in CSS


๐Ÿ“ˆ 21.45 Punkte











matomo