Warning: Undefined array key 0 in /var/www/tgoop/function.php on line 65

Warning: Trying to access array offset on value of type null in /var/www/tgoop/function.php on line 65
424 - Telegram Web
Telegram Web
2. Nesting

In this example, we use nesting to group related CSS rules together. We start with the nav element and nest the ul element inside it. We then nest the li element inside the ul element, and finally nest the a element inside the li element.

By using nesting, we can see the hierarchy of our code more clearly, and it's easier to understand which styles apply to which elements. We also use the & symbol to reference the parent selector, which allows us to create more specific styles for hover states.

#SASS
@javascript_tut @codingWithElias
3. Mixins

In this example, we define a mixin called button-styles that takes two arguments: $bg-color and $text-color. The mixin contains a set of CSS rules that we want to apply to our buttons.

We then use the @include directive to include the button-styles mixin inside two different classes: .button-primary and .button-secondary. We pass different values for the $bg-color and $text-color arguments to create two different styles for our buttons.

By using mixins, we can reuse the same set of CSS rules across multiple classes, making our code more modular and easier to maintain. If we need to update the styles for our buttons, we only need to update the mixin in one place, and the changes will be reflected throughout our code.

#SASS
@javascript_tut @codingWithElias
4. Functions

In this example, we define a function called calculate-width. This function takes three parameters: $container-width, $columns, and $gutter. It calculates the width of each column based on the container width, number of columns, and gutter size, and returns the result.

We then define a .container class with a fixed width of 960px and centered horizontally using margin: 0 auto;.

We also define a .column class with a float: left; and a margin-right: 20px;. The width of each column is calculated using the calculate-width function, passing in the container width of 960px, 3 columns, and a gutter size of 20px.

By using functions, we can write more dynamic and reusable code. We can define complex calculations and reuse them throughout our styles, without having to repeat the same code over and over again. This also makes it easier to maintain our code and make changes to our styles in one place.

#SASS
@javascript_tut @codingWithElias
5. Inheritance

In this example, we define a placeholder selector called %button-styles. This selector sets some basic styles for a button, like background-color, color, padding, and border-radius.

We then define two different button classes: .button-primary and .button-secondary. We use the @extend directive to inherit the styles from the %button-styles placeholder selector.

The .button-primary class inherits all the styles from %button-styles, while the .button-secondary class inherits the same styles but also sets a different background-color and adds a margin-top.

By using inheritance, we can write more modular and reusable code. We can define common styles in a placeholder selector and then inherit those styles in multiple classes, without having to repeat the same code over and over again. This also makes it easier to maintain our code and make changes to our styles in one place.

#SASS
@javascript_tut
@codingWithElias
6. Control Directives

In this example, we define two variables: $primary-color and $secondary-color, and assign them values of #007bff and #6c757d, respectively.

We then define a mixin called button-styles, which takes a parameter called $bg-color. This mixin sets some basic styles for a button, like background-color, color, padding, and border-radius.

We use this mixin to define two different button classes: .button-primary and .button-secondary. We pass the $primary-color and $secondary-color variables as arguments to the button-styles mixin, respectively.

We also use an @if control directive to check if the value of $primary-color is equal to #007bff. If it is, we add a border style to the .button-primary class. If it's not, we remove the border style.

By using control directives, we can write more dynamic and flexible code that can adapt to different situations and conditions.

#SASS
@javascript_tut @codingWithElias
2025/07/05 11:47:50
Back to Top
HTML Embed Code: