Sass Topics
- Sass Introduction
- Sass Installation
- Sass Nested Rules and Properties
- Sass Variables
- Sass @ Rules
- Sass Flow Control
- Sass Operators
- Sass Comments
- Sass Color Functions
- Sass Selector Functions
- Sass Introspection Functions
- Sass Map Functions
- Sass List Functions
- Sass Numeric Functions
- Sass String Functions
Sass to-upper-case() Function
Photo Credit to CodeToFun
đ Introduction
The to-upper-case()
function in Sass is a string function that converts all the characters in a string to uppercase.
This function is particularly useful when you need to standardize or manipulate text in your styles, ensuring consistency across your design.
đĄ Syntax
The syntax of the to-upper-case()
function is straightforward, requiring only a single argument:
to-upper-case(string)
đĸ Parameters
- string: The input string that you want to transform into uppercase letters.
âŠī¸ Return Value
The function returns a new string with all the characters converted to uppercase.
đ Example Usage
Let's look at some examples to see how to-upper-case()
can be applied in various scenarios.
đ Example 1: Basic Usage
$lowercase-string: "hello world";
$uppercase-string: to-upper-case($lowercase-string);
.content {
text-transform: $uppercase-string; // Outputs "HELLO WORLD"
}
In this example, the string "hello world" is converted to "HELLO WORLD" using the to-upper-case()
function.
đ Example 2: Using with Variables
$button-text: "submit";
$button-text-uppercase: to-upper-case($button-text);
button {
content: $button-text-uppercase; // Outputs "SUBMIT"
}
This example shows how you can convert a variable containing lowercase text into uppercase before using it in your styles.
đ Example 3: Dynamic Class Names
$base-name: "primary";
$uppercase-class: to-upper-case($base-name);
.#{$uppercase-class}-button {
background-color: blue;
color: white;
}
In this scenario, the base string "primary" is converted to "PRIMARY", which is then used dynamically to create a class name.
đ Conclusion
The to-upper-case()
function in Sass is a handy utility for transforming text to uppercase. Whether you're working with dynamic class names, standardizing text content, or simply ensuring uniformity in your styles, to-upper-case()
provides a simple and effective way to manage text case in your Sass projects.
Mastering this function can help you streamline your code and maintain consistency across your web design, making your styles more robust and easier to maintain.
đ¨âđģ Join our Community:
Author
For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.
Buy me a coffee to make codetofun.com free for everyone.
Buy me a Coffee
If you have any doubts regarding this article (Sass to-upper-case() Function), please comment here. I will help you immediately.