What does the following code do?
(Assume that the p tag is already made in HTML)
$myrandomcolor: magenta;
p {
color: $myrandomcolor;
}
Makes all paragraph tags have the color magenta
Make a variable to express a color (green) that can be used many times on a website.
Then assign it to a premade p tag.
$coolcolor: green;
p {
color: $coolcolor;
}
Find the error in the code below (1):
/*makes all h1 the color turquoise*/
#h1 {
color: turquoise;
}
There is no need for a hashtag before the h1 tag. You can leave it as the tag name itself when declaring it in the code.
Misleading Question, Can you perform operations (math) in SCSS?
Yes, you can! In both SCSS and CSS, operators are really useful
What does SCSS stand for?
Sassy Cascading Style Sheets
$mycolors: (
primary: #f0f0f0;
accent: #84bef0;
);
h1 {
color: map-get($mycolors, primary);
}
p {
color: map-get($mycolors, accent);
}
Assign the primary color to the h1 selector using and the accent color to the p selector using map-get.
Make a variable called random color that sets one color for all paragraphs and all h1 tags.
$randomcolor: magenta;
h1 {
color: $randomcolor;
}
p {
color: $randomcolor;
}
Find the errors in the code below (2):
%randomcolor: red;
h1 {
randomcolor;
}
There are two errors in the code:
1) The % should be a $.
2) When declaring the randomcolor variable in the h1, there should be a $ before the variable name.
What does @extend do?
@extend allows you to take the properties of one element and add it to another selector. If you have two elements that are in the same SCSS file, then you can use @extend to share the styling of one element to another. This function allows other elements to inherit properties of one element.
What is a CSS preprocessor?
A CSS preprocessor is a program that lets you generate CSS from the preprocessor's own unique syntax. There are many CSS preprocessors, such as SASS, which make the CSS structure more readable and easier to maintain. Also, these preprocessors include added functionality which can be very helpful in many instances.
p {
color: blue;
background-color: green;
font-size: 30px;
}
h1 {
@extend p;
font-family: helvetica;
}
Extend the properties of the paragraph selector to the h1 selector.
Make a map called "mycolor" with a primary and accent color.
primary "green" and accent "blue"
$mycolor: (
primary: green,
accent: blue
);
Find the errors in the code below (3):
&mixed width{
#width: 50px;
}
.box {
&include width;
}
Errors (3)
1) It should be @mixin instead of &mixed.
2) Instead of the "#" in property, it should be a "$".
3) &include should be @include
What does @function do?
@function can allow you to create a function(kind of like in javascript) and call it anywhere in your website
What are key value pairs mainly used for in SCSS?
They are mainly used for maps (map-get) and keys.
@function double($size){
@return $size*2;
}
h1{
font-size: double(12);
}
The function double multiplies the font-size of 12 by 2.
Nest a ul selector inside a p selector inside a nav selector.
nav{
p{
ul{
}
}
}
Find the errors in the code below when importing a partial (2):
@import _test;
1. Should not be _test, instead should just be test
2. Need quotes around the name "test"
What does @mixin do?
In order to call the mixin to use the block of code inside of it what do you use
@mixin allows you to create a block of code you can reuse anywhere in your file
Use @include
Does SCSS Nesting have any particular benefit? If yes, what?
Yes, allows you to organize your code and can allow you to do stuff that you couldn't have done with CSS, such as making only the paragraph tags inside of a div the color red.
@mixin par-text {
color: white;
background-color: blue;
font-family: "poppins";
margin: 50px;
padding: 10px;
}
p.text {
@include par-text;
border:5px solid black;
}
Create a function that adds 5 to the margin measurement for paragraph selectors.
@function margin5($init) {
@return $init + 5;
}
p {
margin: margin5(15);
}
Find the errors in the code (3):
@function double $num {
return: $num*2;
1. Should be parenthesis around $num since it is the parameter
2. Should be @return instead of return:
3. Missing closing brace
@include - adds a mixin and all of its properties to another selector
What is @import used for?
IT is used to add partials to your main SCSS file