Spirit Rising From the Ruins

Despite the deplorable conduct of the regular infantrymen during the attack on York in April, officials in Washington were pleased with the outcome of the invasion headed by General Henry Dearborn…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Tips to Help You Get the Best out of Sass

Sass is the most mature, stable, and powerful professional grade CSS extension language in the world.

Sass creates Syntactically Awesome Style sheets, or at least thats what it is supposed to do.

When used effectively, Sass helps to build scalable and DRY CSS. When used incorrectly however, Sass can actually increase file size and add unnecessary or duplicate code.

Sass is completely compatible with all versions of CSS. We take this compatibility seriously, so that you can seamlessly use any available CSS libraries.

Sass boasts more features and abilities than any other CSS extension language out there. The Sass Core Team has worked endlessly to not only keep up, but stay ahead.

Sass has been actively supported for about 13 years by its loving Core Team.

Over and over again, the industry is choosing Sass as the premier CSS extension language.

Sass is actively supported and developed by a consortium of several tech companies and hundreds of developers.

Install on Mac OS X (Homebrew)

Below is a series of hints and tips to help you get the best out of Sass…

Partial files are created using an underscore and are not output as separate CSS files. Each partial should be imported using a master Sass file (global.scss) in the root of the Sass folder.

For example, here’s a sample folder structure to demonstrate this:

This folder structure ensures the site is easy to work with, and add to.

For example, new modules can easily be added to the module folder and then added to main.scss using @import.

here’s a sample main.scssfile:

Variables are one of the more straightforward features of Sass but are still on occasion used incorrectly. Creating a site-wide naming convention is essential when working with Variables. Without one, they become harder to understand and re-use.

Here are some tips for creating useful variables:

Here are some good examples:

And some bad examples:

A mixin therefore should only be used if an argument is present, to quickly create modified styles.

Here’s an example:

This rounded-corner mixin can be used in any situation simply by changing the value of $arc, making it a worthwhile mixin:

A bad example might look like this:

And the compiled CSS:

The repeated code in the placeholder is output only once with only the unique styles being applied to the individual selectors. If unused, the placeholder styles are not output at all.

Tying in with point 3, placeholders can be used alongside mixins to reduce duplicate code and still keep the flexibility of a mixin…

For example, functions are useful for calculating the percentage width of a given element:

Place all mixins, functions, placeholders and variables in their relevant partial file. Keeping blocks of code together will ensure they are easy to edit and reuse in the future.

Site-wide elements should be kept together in a base folder. The base folder should contain global variables such as fonts and colour schemes:

Module-specific mixins, functions, and variables should be kept within the correct module’s partial file:

Overusing nested rules in Sass can cause a lot of issues, from complex code to over-specificity and too much reliance on the HTML structure of a page. These things can cause issues further down the line and potentially increase the need for the inclusion of !important, which should generally be avoided.

Here are some golden rules for nesting:

The concluding point I’ll make in this post is to keep things as simple as possible. The purpose of Sass is to write cleaner more manageable CSS. Before creating any new mixins, variables, or functions, ensure that their presence will enhance development and not overcomplicate things. All Sass features are useful when used in the correct situations and in moderation.

Creating an endless list of variables without clear usage, or a complex function that is difficult to understand for anyone other than the author is not the intention and will not aid development or produce DRY CSS.

That’s it for this list of Sass tips. You might not agree with all of these. Sass is still a fairly new technology so we’re continuing to learn new best practices with it. If you have your own suggestions, feel free to offer a comment.

Add a comment

Related posts:

A more Realistic technique to Positive Thinking

Positive Thinking has become a big topic especially after the movie ‘The Secret’ that took the world by storm a few years back. I remember how it changed my life as a young teen. Growing up, God was…

Lifevision Baddi is a Leading Pharma Products Manufacturer in India

Lifevision Baddi is a leading Antibiotic Manufacturer in Baddi that has been catering to the healthcare industry for more than two decades. The company is headquartered in Baddi, Himachal Pradesh…

How to teach children to think critically

One of the most important abilities is being able to think critically. Sadly, most of the schools don’t teach it. The importance of it can be seen in day to day life. How to tell apart false…