Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
  • Sass - Get Started
  • What is Sass
  • Sass - Setup Environment
  • Sass - Syntax
  • Sass - Variable
  • Sass - Script
  • Sass - Data Types
  • Sass - Operators
  • Sass - Functions
  • String Functions
  • Numeric Functions
  • List Functions
  • Map Functions
  • Selector Functions
  • Introspection Functions
  • Color Functions
  • Control Directives
  • Import Files and Partials
  • Sass - Mixins
  • Sass - Inheritance
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge

Sass Functions

Next to variables, Sass functions are perhaps the most useful aspect of the language. We'll look at most of them in this chapter and the next few chapters.

In addition to the functions that Sass provides natively, you can also write your own functions in Ruby. But since this is a Sass course, not a Ruby course, we won't be talking about that here. You'll find full documentation on the Sass Documentation.

You can use standard CSS function syntax to call Sass functions:

SCSS: rgb() Function
p {
   color: rgb(42, 154, 179);
}

which will be output as

CSS:
p {
   color: #2a9ab3;
}

Sass also lets you specify the arguments to the function by their name. Most programming languages refer these as to "named parameters", but the Sass documentation calls these "explicit keyword arguments". Whatever you call them, they can be specified in any order:

SCSS:
p {
   color: rgb($red: 42, $blue: 154, $green: 179);
}

Note that the argument names are prefixed with the dollar sign, the same syntax used to identify variables. Fortunately, the Sass transpiler is smart enough to keep them straight:

SCSS:
#argument {
   color: rgb($red: 42, $green: 179, $blue: 154);
}

#variable {
   $red: 42;
   color: rgb($red: $red, $green: 179, $blue: 154);
}

will be output as:

CSS:
#argument {
   color: #2ab39a;
}

#variable {
   color: #2ab39a;
}

Naming your arguments requires a bit more typing, but it does make your intentions clear, and it eliminates the need to memorize (or look up) the order of parameters.

All the function definitions always use the parameter names in this Sass tutorials, do given the declarationstr-insert($string, $insert, $index).

The named parameters (which can be specified in any order) are $string, $insert and $index:str-insert($insert: "hello, ", $string: "world", $index: 1) would return "hello, world".

Sass include various function for string, numeric, list, map, selector and introspection. We will see all these functions in the next few chapters.

Miscellaneous Functions

Sass provides three more functions that don't fit neatly into any of the categories above. Here they are.

FunctionDescriptionExamples
call($name, $args..)Calls a Sass or CSS function, passing any remaining arguments to the functioncall(floor, 3, 5, 7, 1)
Result: 1
if($condition, $if-true, $if-false)Returns $if-true if $condition evaluates to true, otherwise returns $if-false.if(1==1, 10px, 20px)
Result: 10px
unique-id()Returns a random unique CSS identifierunique-id()
Result: "utewylqbn"

Learn about string, numeric, list, map, selector and introspection functions in the next few chapters.

Find the full list of Sass functions at the Sass website.

TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

[email protected]

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.