SASS Tutorial (build your own CSS library) #10 - Conditionals (@if)
Skills:
HTML & CSS80%
Key Takeaways
This video tutorial covers the use of conditionals, specifically if statements, in SASS to generate styles and selectors based on certain conditions, and demonstrates how to use them in a CSS library.
Full Transcript
all right then gang so the next thing i'd like to talk about is conditionals or if statements in sas now if you're familiar with another programming language this is going to come as second nature to you because it's just like a normal if else statement so what we can do is basically check a certain condition with this and if that condition is true then we can maybe generate some styles or selectors or whatever and if it's false we can do something else so let's do a simple example i'm still in the colors file i'm just going to say at the bottom at if and then parentheses and then this is where the condition goes so i could just say in this example if 10 is greater than 5 then we're going to do something now that is obviously true so if that's true then we're going to say test if and just say color is black just to see if this works right so i'm going to save this now and then i'm going to check the index file and i'm going to look for oops let's close that i'm going to look for test hyphen if and we can see now we have that class however if i say 10 is less than 5 that's obviously false if i save this then that style is gonna go all right then so this is gonna be useful inside our different color utility classes right here because if we go back to the index file notice this we've got things like this bg hi from white hyphen dark and we've got bg white hyphen light as well or text hyphen white hyphen light and they're all white we don't need to create these dark and light variations of black and white we just want something like bg hyphen white or text hyphen white we don't need these different variations so what i could do is use an if statement like this to check if we're currently iterating through the black or light color now if we are then we don't want to run this code right here we don't want to generate those extra light and dark variation utility classes if we're not then we will go ahead and do that by the way you can also add on an else clause right here so you can say if 10 is less than 5 do this and then you can say test if 2 and what we'll say is color is white and basically what this is saying is if 10 is less than 5 then do this else if it's not then we'll have this class instead so if i save this now i'm just going to look for test if again and we can see we get test if two all right so enough of that let's try using this if statement inside here so what i'm going to do is above this light variation is create this if statement because we still want these general utility classes for black and white we don't want to enclose those inside the if statement we just don't want the light and dark variations okay so inside here i'm going to do a condition and that condition is going to be if the value right here is going to be black or rather if it's not equal to black and remember that's what the value of this is right here black and white right there the values and we're saying if the value is not equal to black and then we can say and because we want to make sure it's not equal to white as well so the vowel is not equal to white then we're going to run the code down here so let me take the closing curly brace and place that at the end of this for loop like so and skew all of this in so we're saying if the value is not equal to black and it's not equal to white then we can run this now if we're iterating through this loop here and we get to the black value then this right here is going to be false because this right here is false okay so in that case we're not going to create the variations and likewise for white as well so if i was to save this now and we're going to go into the css hopefully if i search for test hyphen black oops not test it should be text hyphen black then we can see we don't get those variations we just get the background black and the text black and the same for white as well but for all the other colors we get the different variations
Original Description
Hey gang, you'll learn about conditionals (if checks) & how to use them in this SASS tutorial.
🐱👤 Get the full SASS course now on Net Ninja Pro:
https://netninja.dev/p/complete-sass-tutorial
🐱👤 Get access to all other premium courses on Net Ninja Pro:
https://netninja.dev/
🐱💻 Access the course files on GitHub:
https://github.com/iamshaunjp/complete-sass-tutorial
🐱💻 HTML & CSS Crash Course:
On Net Ninja Pro - https://netninja.dev/p/html-css-crash-course
On YouTube - https://www.youtube.com/watch?v=hu-q2zYwEYs&list=PL4cUxeGkcC9ivBf_eKCPIAYXWzLlPAm6G
🐱💻 Modern JavaScript Course:
On Net Ninja Pro - https://netninja.dev/p/modern-javascript-from-novice-to-ninja
On YouTube - https://www.youtube.com/watch?v=iWOYAxlnaww&list=PL4cUxeGkcC9haFPT7J25Q9GRB_ZkFrQAc
🐱💻 CSS Flexbox Course (on YouTube):
https://www.youtube.com/watch?v=Y8zMYaD1bz0&list=PL4cUxeGkcC9i3FXJSUfmsNOx8E7u6UuhG
🐱💻 SASS docs - https://sass-lang.com/documentation
🐱💻 VS Code - https://code.visualstudio.com/
-------------- Net Ninja Links:
🐱💻 My Social Links:
Facebook - https://www.facebook.com/thenetninjauk
Twitter - https://twitter.com/thenetninjauk
Instagram - https://www.instagram.com/thenetninja/
🐱👤 Get access premium courses on Net Ninja Pro:
https://netninja.dev/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Net Ninja · Net Ninja · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
GraphQL Tutorial #5 - Express App Setup
Net Ninja
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
GraphQL Tutorial #8 - Root Query
Net Ninja
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
GraphQL Tutorial #12 - Author Type
Net Ninja
GraphQL Tutorial #13 - Type Relations
Net Ninja
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
GraphQL Tutorial #18 - Mutations
Net Ninja
GraphQL Tutorial #19 - More on Mutations
Net Ninja
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
GraphQL Tutorial #23 - Create React App
Net Ninja
GraphQL Tutorial #24 - Book List Component
Net Ninja
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
GraphQL Tutorial #28 - Add Book Component
Net Ninja
GraphQL Tutorial #29 - External Query File
Net Ninja
GraphQL Tutorial #30 - Updating Component State
Net Ninja
GraphQL Tutorial #31 - Composing Queries
Net Ninja
GraphQL Tutorial #32 - query variables
Net Ninja
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
GraphQL Tutorial #34 - Book Details Component
Net Ninja
GraphQL Tutorial #36 - Styling the App
Net Ninja
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
Updated Vue & Firebase Course (Udemy)
Net Ninja
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja
More on: HTML & CSS
View skill →Related Reads
📰
📰
📰
📰
Inside the Wayfair Frontend SDE-2 Interview: A Complete Breakdown
Medium · Programming
I Spent Two Years Maintaining a React SPA. HTMX Rebuilt It in a Week
Medium · Programming
The 5 Levels of Front End Engineering (And Where Most Developers Get Stuck)
Medium · Programming
Browser-Based PDF Editing with Vue 3 and pdf-lib
Dev.to · sunshey
🎓
Tutor Explanation
DeepCamp AI