A convenient Scss library for quick use.
If you prefer Scss development and need to collaborate with UI/UX designers following the guidelines, this Library is perfect for you!
Of course, you can also easily extend and maintain this framework!
You can use it directly in your project. It supports Vue, React, Nuxt, and Next.
If there are any improvements that can be made, feel free to send a PR after messaging me.
https://github.com/fortes1219/scss-base-library
Since the author of SassMeister announced on Twitter that it is shut downif the website is not accessible, it is recommended to use https://sass.js.org/ for preview.
Before reading this document, please be aware of a few things.
If your project does not need to consider changing skins, you can continue to use TailwindCSS, Stylus, bootstrap, or other methods you are familiar with or consider faster.
As browser versions update, the content will be revised periodically. Since I use this library regularly, I might add new features, such as the recently usable :has().
This library essentially needs to follow themes defined with tools like Figma or XD. If you have a designer who can accurately specify each theme color, typography, spacing, and easing, treat them well. It will greatly help with your skin-changing tasks and redesigns.
Applicable Version: Sass 1.50.1 +
Testing Tool: Recommended to use Sass.js
It is recommended to open the image in a new window: https://i.imgur.com/J3hNFJT.png
Live Code: https://codepen.io/fortes-huang/pen/gOdJOWG
Path: src/style/config/_theme.scss
There are two ways to extract theme colors defined in Figma.
Automatically generate CSS through map traversal and apply it directly.
The generated CSS will look like this:
Apply it to any color or background.
Here is an overview of how to define the typographic system in your project.
Live Code: https://codepen.io/fortes-huang/pen/XWPwbXE
heading text h1 to h6
Font size settings, color matching, and specifying breakpoints to apply text-overflow: ellipsis
path:src/style/config/_typography.scss
Here we use mixins for text overflow.
path:src/style/config/_mixins.scss
useEllipsis is used in typography.scss
A method to convert px to rem or rem to px.
path:src/style/config/_remAdaptor.scss
If your project and designer have agreed to use proportional scaling to display the mobile site appearance, you will likely need to set up something like this for your project:
https://github.com/fortes1219/scss-base-library/blob/master/rem.js
This script sets the font-size to 100px at a default resolution of 390x884 (iPhone 12/13). The purpose is to dynamically change the body font-size so that the UI's width and height are calculated in rem units, facilitating proportional scaling.
path:src/style/config/_flexbox.scss
Live Code (codepen): https://codepen.io/fortes-huang/pen/OJVyVxw
result:
Generally, there is no need to set flex-shrink (shrink ratio), flex-basis (initial width).
If you need to make elements stick to the left and right edges of the parent container after wrapping, using Grid is more ideal.
This is because flexbox is designed to solve the layout problem with a "single row" premise. Using only flexbox makes the code relatively complex to maintain.
You can refer to the following flexList to see what conditions are needed.
Using flexbox for list items, you need to specify the number of columns in each row, the arrangement, and the width and height of the child elements.
Live Code: https://codepen.io/fortes-huang/pen/jOvKZOr
Regarding the implementation principle, let's look at an example:
Suppose the width of each child element card is calc(100%/5)
, using space-between
to align the container left and right:
Here, align-content: start
is used in .wrap
, preventing the height between two lines from being increased after wrapping.
Settings to remove the margin for the last element (5n) of each row:
If there is only one element in the second row, it's fine, but if there are more…
space-between
will separate the two elements in the second row, and it won't work for just one element.
The more extra space, the larger the gap.
Therefore, we use Pseudo Element: after to fill the unhandled space:
And add the mixin for child element list items:
This way, you can smoothly customize the list regardless of the number of child elements.
Live Code: https://codepen.io/fortes-huang/pen/VwGELJq
If flex-direction: column is the basis
, another method will be used, and justify-content
must be flex-start
.
To center the child elements, add align-content: center to the parent container, like this:
path:src/style/config/_grid.scss
Live Code (codepen): https://codepen.io/fortes-huang/pen/wvEYOPG
Usage:
Source Code:
The way to write a grid list:
$rows
=> Number of elements in one row
$gap
=> Spacing between elements
$autoSize
=> Used to specify the minimum height of each element, accepting 'auto' / null / any unit height
When the content height of a specific element in a row is higher than other elements, it will automatically stretch the height of all sibling elements in that row.
In conclusion, this SCSS library provides a robust and flexible foundation for building scalable and maintainable styles in your projects. By standardizing configurations for colors, typography, spacing, and responsive design, you can ensure consistency and efficiency in your development process. We hope you find these tools and techniques useful in your work.
We are continuously working to improve this library. Future updates may include additional mixins, extended support for new CSS features, and more examples to demonstrate best practices. Stay tuned for more enhancements and feel free to contribute your ideas.
We would like to thank all the contributors and community members who have provided feedback and suggestions. Your support and collaboration are invaluable to the success of this project.
Scss
Scss Library
Scss Optimization
, SCSS best practices