SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
CSS
Variables
Native reusable
custom properties
#iscss@evalica
● The property is an identifier that defines
which feature is considered
● The value describe how the feature must be
handle by the engine
● A property and value pair is called a
declaration
● Declarations are grouped in blocks
● Each block is preceded by a selector
CSS Syntax
● CSS custom properties (variables)
● Property names that are prefixed with --, like
--example-name, represent custom properties
that contain a value that can be reused
throughout the document using the var()
function
● Are subject to the cascade and inherit their
value from their parent
CSS Variables
CSS Preprocessors
CSS Preprocessing
Variables Variants
CSS Saas LESS CSS Variables
Launched 1996 2006 2009 2012
Author W3C Hampton Catlin Alexis Sellier W3C
Type Native CSS Preprocessor CSS Preprocessor Native
Filename .css .css, .scss, .sass .css, .less .css
Syntax $* @* --*
Runtime static static dynamic
CSS VariablesCSS
a:hover {
color: #150C55;
}
LESS SCSS
:root {
--color: #150C55;
}
a:hover {
color: var(--color);
}
@color: #150C55;
a {
&:hover {
color: @color;
}
}
$color: #150C55;
a {
&:hover {
color: $color;
}
}
Example 1: Scope
http://bit.ly/CSSVar1F
AAnswer :
Sass
$var: 10px;
#id1 {
$var: 12px;
font-size: $var;
}
#id2 {
font-size: $var;
}
LESS
@var: 10px;
#id1 {
@var: 12px;
font-size: @var;
}
#id2 {
font-size: @var;
}
CSS
#id1 {
$var: 12px !global;
}
#id1 {
font-size: 12px;
}
#id2 {
font-size: 10px;
}
#id2 {
font-size: 12px;
}
@var: 12px;
Example 2: Computed value time
http://bit.ly/CSSVar2F
AAnswer :
http://bit.ly/CSSVar3F
BAnswer :
Example 3: Fallback
http://bit.ly/CSSVar4F
Verdana,
sans-serifAnswer :
Example 4: Fallback
BAnswer :
http://bit.ly/CSSVar5F
Example 5: Dynamic Media
Other examples
a:lang(en) {--external-link: "external link";}
a:lang(de) {--external-link: "externer Link";}
a[href^="http"]::after {
content: " (" var(--external-link) ")"
}
:root {
--hue: 247; --saturation: 75%; --lightness: 19%;
--shader: 50%;
--lightLighter: calc( var(--lightness) + var(--shader) );
--satLighter: calc( var(--saturation) - var(--shader) );
--mainColorLighter: hsl( var(--hue), var(--satLighter),
var(--lightLighter) );
}
div {
background: hsla( var(--hue), var(--saturation),
var(--lightness) );
color: var(--mainColorLighter);
}
:root {
--color-1: blue;
color: green;
}
.MyID {
Color: Red;
color: var(--coloR-1);
}
A
B
C
● currentColor was the first CSS Variable
● Are subject to the cascade and inherit their value from their parent
● Can provide one or more fallback value/s
● Are case sensitive
● Are dynamic, can be changed in different scopes and at runtime
● Can be used in combination with calc(), SVG, @media, @keyframes animations, etc.
Conclusions: CSS Variables
Can I use?
CSS Variables
(Custom Properties)
Permits the declaration and usage of
cascading variables in stylesheets
87.73% APR 2018
body {
--bg-color: #150C55;
background-color: pink;
}
@supports (background-color: var(--bg-color)) {
body {
background-color: var(--bg-color);
}
}
Thank you
@evalica #iscss
References
● CSS Custom Properties for Cascading Variables
Module Level 1
● MDN: Custom properties (--*)
● CSS Variables: Why Should You Care?
● The Evolution of CSS
● CSS [Variable] Secrets
● Naming decision
● Difference between types of css variables
● CSS Custom Properties explained
● CSS Variables Performance
● Why I Abandoned @apply
● 6 Preprocessor Features Coming to CSS
Quiz Answers
● Example 1 (Slide 8) — A
● Example 2 (Slide 10) — A
● Example 3 (Slide 11) — B
● Example 4 (Slide 12) — /
● Example 5 (Slide 13) — B

Weitere ähnliche Inhalte

Ähnlich wie CSS Variables — Native reusable custom properties

CSS preprocessor: why and how
CSS preprocessor: why and howCSS preprocessor: why and how
CSS preprocessor: why and howmirahman
 
CSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassCSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassLucien Lee
 
Deep dive into sass
Deep dive into sassDeep dive into sass
Deep dive into sassKnoldus Inc.
 
Scaling web applications with cassandra presentation
Scaling web applications with cassandra presentationScaling web applications with cassandra presentation
Scaling web applications with cassandra presentationMurat Çakal
 
Simple introduction Sass
Simple introduction SassSimple introduction Sass
Simple introduction SassZeeshan Ahmed
 
LESS(CSS preprocessor)
LESS(CSS preprocessor)LESS(CSS preprocessor)
LESS(CSS preprocessor)VIPIN KUMAR
 
Implementing CSS support for React Native
Implementing CSS support for React NativeImplementing CSS support for React Native
Implementing CSS support for React NativeKristerKari
 
Raleigh Web Design Meetup Group - Sass Presentation
Raleigh Web Design Meetup Group - Sass PresentationRaleigh Web Design Meetup Group - Sass Presentation
Raleigh Web Design Meetup Group - Sass PresentationDaniel Yuschick
 
Introduction to Apache HBase, MapR Tables and Security
Introduction to Apache HBase, MapR Tables and SecurityIntroduction to Apache HBase, MapR Tables and Security
Introduction to Apache HBase, MapR Tables and SecurityMapR Technologies
 
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
Bringing sexy back to CSS: SASS/SCSS, LESS and CompassBringing sexy back to CSS: SASS/SCSS, LESS and Compass
Bringing sexy back to CSS: SASS/SCSS, LESS and CompassClaudina Sarahe
 
Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018
Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018
Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018Codemotion
 
Finding your way with Sass+Compass
Finding your way with Sass+CompassFinding your way with Sass+Compass
Finding your way with Sass+Compassdrywallbmb
 
Learn Sass and Compass quick
Learn Sass and Compass quickLearn Sass and Compass quick
Learn Sass and Compass quickBilly Shih
 
Compass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperCompass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperWynn Netherland
 
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsMobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsKaelig Deloumeau-Prigent
 

Ähnlich wie CSS Variables — Native reusable custom properties (20)

CSS preprocessor: why and how
CSS preprocessor: why and howCSS preprocessor: why and how
CSS preprocessor: why and how
 
CSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & CompassCSS 開發加速指南-Sass & Compass
CSS 開發加速指南-Sass & Compass
 
Deep dive into sass
Deep dive into sassDeep dive into sass
Deep dive into sass
 
SASS Lecture
SASS Lecture SASS Lecture
SASS Lecture
 
Scaling web applications with cassandra presentation
Scaling web applications with cassandra presentationScaling web applications with cassandra presentation
Scaling web applications with cassandra presentation
 
Simple introduction Sass
Simple introduction SassSimple introduction Sass
Simple introduction Sass
 
LESS(CSS preprocessor)
LESS(CSS preprocessor)LESS(CSS preprocessor)
LESS(CSS preprocessor)
 
Implementing CSS support for React Native
Implementing CSS support for React NativeImplementing CSS support for React Native
Implementing CSS support for React Native
 
Raleigh Web Design Meetup Group - Sass Presentation
Raleigh Web Design Meetup Group - Sass PresentationRaleigh Web Design Meetup Group - Sass Presentation
Raleigh Web Design Meetup Group - Sass Presentation
 
Advanced sass
Advanced sassAdvanced sass
Advanced sass
 
Introduction to Apache HBase, MapR Tables and Security
Introduction to Apache HBase, MapR Tables and SecurityIntroduction to Apache HBase, MapR Tables and Security
Introduction to Apache HBase, MapR Tables and Security
 
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
Bringing sexy back to CSS: SASS/SCSS, LESS and CompassBringing sexy back to CSS: SASS/SCSS, LESS and Compass
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
 
Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018
Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018
Joan Leon | Houdini, programando en CSS | Codemotion Madrid 2018
 
CSS - Basics
CSS - BasicsCSS - Basics
CSS - Basics
 
NoSql Database
NoSql DatabaseNoSql Database
NoSql Database
 
Finding your way with Sass+Compass
Finding your way with Sass+CompassFinding your way with Sass+Compass
Finding your way with Sass+Compass
 
Learn Sass and Compass quick
Learn Sass and Compass quickLearn Sass and Compass quick
Learn Sass and Compass quick
 
Compass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS DeveloperCompass, Sass, and the Enlightened CSS Developer
Compass, Sass, and the Enlightened CSS Developer
 
Intro to SASS CSS
Intro to SASS CSSIntro to SASS CSS
Intro to SASS CSS
 
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive NewsMobile-first OOCSS, Sass & Compass at BBC Responsive News
Mobile-first OOCSS, Sass & Compass at BBC Responsive News
 

Mehr von Ecaterina Moraru (Valica)

UI/UX Tips & Tricks for developers - FOSDEM2020
UI/UX Tips & Tricks for developers - FOSDEM2020UI/UX Tips & Tricks for developers - FOSDEM2020
UI/UX Tips & Tricks for developers - FOSDEM2020Ecaterina Moraru (Valica)
 
Difficulties in having more designers participate in Open Source
Difficulties in having more designers participate in Open SourceDifficulties in having more designers participate in Open Source
Difficulties in having more designers participate in Open SourceEcaterina Moraru (Valica)
 
Interconectarea Semantica A Datelor In Contextul Managementului Informatiilor...
Interconectarea Semantica A Datelor In Contextul Managementului Informatiilor...Interconectarea Semantica A Datelor In Contextul Managementului Informatiilor...
Interconectarea Semantica A Datelor In Contextul Managementului Informatiilor...Ecaterina Moraru (Valica)
 
Tehnici De Tip Mashup Pentru Interactiuni Web In Sisteme Informationale Geogr...
Tehnici De Tip Mashup Pentru Interactiuni Web In Sisteme Informationale Geogr...Tehnici De Tip Mashup Pentru Interactiuni Web In Sisteme Informationale Geogr...
Tehnici De Tip Mashup Pentru Interactiuni Web In Sisteme Informationale Geogr...Ecaterina Moraru (Valica)
 

Mehr von Ecaterina Moraru (Valica) (20)

UI/UX Tips & Tricks for developers - FOSDEM2020
UI/UX Tips & Tricks for developers - FOSDEM2020UI/UX Tips & Tricks for developers - FOSDEM2020
UI/UX Tips & Tricks for developers - FOSDEM2020
 
UI/UX Tips & Tricks for developers
UI/UX Tips & Tricks for developersUI/UX Tips & Tricks for developers
UI/UX Tips & Tricks for developers
 
Sketching Session
Sketching SessionSketching Session
Sketching Session
 
CSS Grid vs. Flexbox
CSS Grid vs. FlexboxCSS Grid vs. Flexbox
CSS Grid vs. Flexbox
 
Designing in the open
Designing in the openDesigning in the open
Designing in the open
 
XWiki Skin 10.x+ ideas
XWiki Skin 10.x+ ideasXWiki Skin 10.x+ ideas
XWiki Skin 10.x+ ideas
 
Difficulties in having more designers participate in Open Source
Difficulties in having more designers participate in Open SourceDifficulties in having more designers participate in Open Source
Difficulties in having more designers participate in Open Source
 
Icon Themes
Icon ThemesIcon Themes
Icon Themes
 
Design proposals status 9.x
Design proposals status 9.xDesign proposals status 9.x
Design proposals status 9.x
 
What's new in XWiki 8.x and half of 9.x
What's new in XWiki 8.x and half of 9.x What's new in XWiki 8.x and half of 9.x
What's new in XWiki 8.x and half of 9.x
 
Expectations from Open Source Designers
Expectations from Open Source DesignersExpectations from Open Source Designers
Expectations from Open Source Designers
 
Success stats from OSD community
Success stats from OSD communitySuccess stats from OSD community
Success stats from OSD community
 
Future of XWiki Skins
Future of XWiki SkinsFuture of XWiki Skins
Future of XWiki Skins
 
Design process in an Open Community
Design process in an Open CommunityDesign process in an Open Community
Design process in an Open Community
 
XWiki Usability Testing Sessions
XWiki Usability Testing SessionsXWiki Usability Testing Sessions
XWiki Usability Testing Sessions
 
About XWiki.org
About XWiki.orgAbout XWiki.org
About XWiki.org
 
Evolution of CSS
Evolution of CSSEvolution of CSS
Evolution of CSS
 
XWiki Improvements Review (ver 2.4 - 5.1)
XWiki Improvements Review (ver 2.4 - 5.1)XWiki Improvements Review (ver 2.4 - 5.1)
XWiki Improvements Review (ver 2.4 - 5.1)
 
Interconectarea Semantica A Datelor In Contextul Managementului Informatiilor...
Interconectarea Semantica A Datelor In Contextul Managementului Informatiilor...Interconectarea Semantica A Datelor In Contextul Managementului Informatiilor...
Interconectarea Semantica A Datelor In Contextul Managementului Informatiilor...
 
Tehnici De Tip Mashup Pentru Interactiuni Web In Sisteme Informationale Geogr...
Tehnici De Tip Mashup Pentru Interactiuni Web In Sisteme Informationale Geogr...Tehnici De Tip Mashup Pentru Interactiuni Web In Sisteme Informationale Geogr...
Tehnici De Tip Mashup Pentru Interactiuni Web In Sisteme Informationale Geogr...
 

Kürzlich hochgeladen

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 

Kürzlich hochgeladen (20)

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 

CSS Variables — Native reusable custom properties

  • 2. ● The property is an identifier that defines which feature is considered ● The value describe how the feature must be handle by the engine ● A property and value pair is called a declaration ● Declarations are grouped in blocks ● Each block is preceded by a selector CSS Syntax
  • 3. ● CSS custom properties (variables) ● Property names that are prefixed with --, like --example-name, represent custom properties that contain a value that can be reused throughout the document using the var() function ● Are subject to the cascade and inherit their value from their parent CSS Variables
  • 6. Variables Variants CSS Saas LESS CSS Variables Launched 1996 2006 2009 2012 Author W3C Hampton Catlin Alexis Sellier W3C Type Native CSS Preprocessor CSS Preprocessor Native Filename .css .css, .scss, .sass .css, .less .css Syntax $* @* --* Runtime static static dynamic
  • 7. CSS VariablesCSS a:hover { color: #150C55; } LESS SCSS :root { --color: #150C55; } a:hover { color: var(--color); } @color: #150C55; a { &:hover { color: @color; } } $color: #150C55; a { &:hover { color: $color; } }
  • 9. Sass $var: 10px; #id1 { $var: 12px; font-size: $var; } #id2 { font-size: $var; } LESS @var: 10px; #id1 { @var: 12px; font-size: @var; } #id2 { font-size: @var; } CSS #id1 { $var: 12px !global; } #id1 { font-size: 12px; } #id2 { font-size: 10px; } #id2 { font-size: 12px; } @var: 12px;
  • 10. Example 2: Computed value time http://bit.ly/CSSVar2F AAnswer :
  • 14. Other examples a:lang(en) {--external-link: "external link";} a:lang(de) {--external-link: "externer Link";} a[href^="http"]::after { content: " (" var(--external-link) ")" } :root { --hue: 247; --saturation: 75%; --lightness: 19%; --shader: 50%; --lightLighter: calc( var(--lightness) + var(--shader) ); --satLighter: calc( var(--saturation) - var(--shader) ); --mainColorLighter: hsl( var(--hue), var(--satLighter), var(--lightLighter) ); } div { background: hsla( var(--hue), var(--saturation), var(--lightness) ); color: var(--mainColorLighter); } :root { --color-1: blue; color: green; } .MyID { Color: Red; color: var(--coloR-1); } A B C
  • 15. ● currentColor was the first CSS Variable ● Are subject to the cascade and inherit their value from their parent ● Can provide one or more fallback value/s ● Are case sensitive ● Are dynamic, can be changed in different scopes and at runtime ● Can be used in combination with calc(), SVG, @media, @keyframes animations, etc. Conclusions: CSS Variables
  • 16. Can I use? CSS Variables (Custom Properties) Permits the declaration and usage of cascading variables in stylesheets 87.73% APR 2018 body { --bg-color: #150C55; background-color: pink; } @supports (background-color: var(--bg-color)) { body { background-color: var(--bg-color); } }
  • 18. References ● CSS Custom Properties for Cascading Variables Module Level 1 ● MDN: Custom properties (--*) ● CSS Variables: Why Should You Care? ● The Evolution of CSS ● CSS [Variable] Secrets ● Naming decision ● Difference between types of css variables ● CSS Custom Properties explained ● CSS Variables Performance ● Why I Abandoned @apply ● 6 Preprocessor Features Coming to CSS
  • 19. Quiz Answers ● Example 1 (Slide 8) — A ● Example 2 (Slide 10) — A ● Example 3 (Slide 11) — B ● Example 4 (Slide 12) — / ● Example 5 (Slide 13) — B