August 2023 to June 2024
View the Project on GitHub IshanCornick/new_student
SASS is a preprocessor scripting language that is interpreted or compiled into CSS. Any preprocessor language takes input data and converts it to an output that’s used as input by another program. In other words when you run a SASS code you are actually converting your code into CSS which is then used by the browser.
CSS: Cascading style sheets or CSS is the standard styling language for the web which provides a simple and direct syntax for styling HTML elements.
However , it lacks certain features found in preprocessors like Sass, making it less understandable and difficult to work with.
// Basic CSS Code
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
}
header {
background-color: #333;
color: white;
padding: 10px;
}
// Basic SASS Code
$font-family: Arial, sans-serif;
$background-color: #f0f0f0;
$main-color: #333;
$link-color: #444;
$border-color: #ddd;
body {
font-family: $font-family;
background-color: $background-color;
}
header {
background-color: $main-color;
color: white;
padding: 10px;
}
Write a line of code to compare CSS and SASS. Must be similar is both languages. Show how SASS and CSS are similar but different.
// Your code here
Improved Code Organization
Maintainability
Advanced Features
Preprocessing:
No, not that type of nesting
- Nesting: Nesting in coding, especially in stylesheets like SASS, is a way of organizing code by putting one selector inside another. Sort of a hirarchy in structure.
// Nesting example
article {
border: 1px solid #ccc;
h2 {
font-size: 20px;
color: #555;
}
p {
font-size: 16px;
color: #333;
margin-bottom: 10px;
}
a {
text-decoration: underline;
color: #007bff;
}
}
Operators Reference Table
Operator | Definition |
---|---|
== | Check if two values are equal |
!= | Check if two values are not equal |
+ | Add two values together |
- | Subtract two values |
* | Multiply two values |
/ | Divide two values |
% | Find the remainder of two values |
< | Check if one value is less than another |
> | Check if one value is greater than another |
<= | Check if one value is less than or equal to another |
>= | Check if one value is greater than or equal to another |
// Variables
$firstName: "John";
$lastName: "Doe";
// String concatenation using whitespace
$fullName: $firstName + " " + $lastName;
#testing {
content: $fullName;
}
Intended Answer: content: John Doe
// example code
$grade: 85;
.button {
@if $grade >= 90 {
background-color: green;
color: white;
border: 2px solid darkgreen;
} @else if $grade >= 80 {
background-color: yellow;
color: darkgray;
border: 2px solid goldenrod;
} @else {
background-color: red;
color: white;
border: 2px solid darkred;
}
}
Write a simple SASS code to highlight a message box according to it’s result, green for success, yellow for warning and red for an error. Use the variable “$message-type”. Make sure to use @if, @else and @else if statements.
// Your code here
// Example code
$alignments: left, center, right;
@each $alignment in $alignments {
.text-#{$alignment} {
text-align: $alignment;
}
}
// Expected output
.text-left {
text-align: left;
}
.text-center {
text-align: center;
}
.text-right {
text-align: right;
}
Write a simple SASS code that defines three different font sizes, which iterates over the same line distance of 1.5.
// Your code here
Last but not the least SASS functions.
Built in Functions
Creating Custom Functions
In addition to built in functions one can also create custom functions with pre exisiting operators and the @return function.
// Example of a complete SASS Code from CSS of Previous CPT Project
$main-bg-color: #8ec1da;
$card-bg-color: rgba(128, 128, 128, 0.5);
$button-bg-color: rgba(38, 152, 255, 0.5);
$button-hover-bg-color: rgba(38, 152, 255, 0.3) !important;
$font-family: Verdana, sans-serif;
$button-size: 10%;
$box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
body {
width: 100%;
height: 100%;
margin: 0em 0%;
background-color: $main-bg-color;
background-image: url("https://static.vecteezy.com/system/resources/previews/016/124/733/non_2x/poker-and-casino-playing-card-black-background-vector.jpg");
background-position: center bottom;
}
.title, .playercardsbox, .dealercardsbox, .result, .hitbutton, .standbutton, .resetbutton, .playersumbox, .dealersumbox {
position: fixed;
transform: translate(-50%, -50%);
font-family: $font-family;
}
.playercardsbox, .dealercardsbox, .playersumbox, .dealersumbox {
background-color: $card-bg-color;
padding: 20px;
border-radius: 10px;
box-shadow: $box-shadow;
font-size: 30px;
}
.result {
top: 34%;
font-size: 150px;
color: red;
display: none;
}
.hitbutton, .standbutton, .resetbutton {
left: 50%;
background-color: $button-bg-color;
border: none;
width: $button-size;
height: $button-size;
border-radius: 10px;
font-size: 30px;
}
.hitbutton:hover, .standbutton:hover, .resetbutton:hover {
background-color: $button-hover-bg-color;
}
.standbutton { top: 72%; }
.hitbutton { top: 60%; }
.resetbutton { top: 84%; display: block; }
In HTML, you don’t directly use Sass; instead, you use the compiled CSS generated from Sass.
npm install -g sass
// Example sass
$primary-color: #3498db;
body {
background-color: $primary-color;
}
sass input.scss output.css
<html>
<head>
<!--Meta data here -->
<link rel="stylesheet" href="output.css">
<title>Project Page</title>
</head>
<body>
<!--HTML stuff-->
</body>
</html>
// Your code here