The main aim of the library is to speedup up the website development process with the usage of simple utility classes.
The utility classes can be used to modify web page elements in tablets
and phones
without needing to make any CSS changes.
It also contains a small set of useful SASS mixins.
All of the CSS classes support usage in phones and tables through media queries. You simply need to add the device category specific prefix to make them device specific. The default prefixes are: tab-
, phn-tab-
, phn-
(These can be changed in config)
For example, For modifying the display property of a div in different devices:
<div class="block phn-inline-block">I will change to inline block when viewed on a phone</div>
Similarly for changing margin or padding:
<div class="pad-30 mar-60 tab-pad-20 tab-mar-40 phn-pad-10 phn-mar-20">My margin and padding will change in tablet and phone</div>
This is just a simple example. The classes can be used to modify even a single property like this:
<div class="pad-30 mt-60 phn-pv-20 phn-mt-20">My top margin and vertical padding will change in phone</div>
Just copy the directory to your project and import using:
@import "sass-css-utilities/sass-css-utilities";
If you want to change configuration, declare the configuration variables before importing the library. (In different file, or on top of import statement. Check style.scss for example)
fl
: Float leftfr
: Float rightfn
orfloat-none
: Float noneclr
orclear
: Clear bothcf
orclearfix
: Clear fix
width-auto
: width:autowidth-fill
: width:auto, display: block, overflow: hiddenwidth-full
: width:100%width-full-alt
: width:100%, display: block, box-sizing: border-box
ta-c
oralign-center
: Text align centerta-l
oralign-left
: Text align leftta-r
oralign-right
: Text align right
va-top
oralign-top
: Vertical align topva-middle
oralign-middle
: Vertical align middleva-bottom
oralign-bottom
: Vertical align bottomva-baseline
oralign-baseline
: Vertical align baseline
hide
orhidden
: display:noneinvisible
: visibility: hiddentransparent
: opacity 0opaque
: opacity 1inline
: display:inlineblock
: display:blockinline-block
: display:inline-block, max-width:100%table
: display: tabletable-cell
: display: table-celltable-row
: display: table-rowborder-box
: border-box box model
hide-text
: Hides text using text-index techniqueellipsis
: Truncates text with ellipsistext-break
: word-wrap: break-wordnon-selectable
ordisable-text-select
: Disables text selectionuc
oruppercase
: Transforms text to uppercaselc
orlowercase
: Transforms text to lowercase
normal
: font-weight: normalbold
: font-weight: bolditalic
: font-style: italicline-through
: text-decoration: line-through
inherit-color
: color: inherit
pos-relative
: Relative positionpos-absolute
: Absolute positionpos-fixed
: Fixed position, includes backface-visibility: hiddenpos-static
: Static position
clickable
: cursor:pointerlink
: text-decoration: none, on hover and focus: text-decoration: underlinelink-clean
: text-decoration: none for every statelink-block
: display: block, text-decoration: none
border-radius($radius)
border-radius-top-left($radius)
border-radius-top-right($radius)
border-radius-bottom-left($radius)
border-radius-bottom-right($radius)
bg-image-2x($file, $type, $bg-size:false)
: Example: $file: "trip", $type: "png", $bg-size: "200px 100px" will use trip@2x.png for retina devices.
at-least-width($device-width)
: Devices with min width as specifieduntil-width($device-width)
: Devices with max width as specifiedif-device($device)
: Media query specific to a device. Possible values aretablet
,phone-tablet
andphone
.
Device width config can be updated with these variables:
$scu-phone-max-width : 767px;
$scu-tablet-min-width : 768px;
$scu-tablet-max-width : 979px;
$scu-desktop-min-width : 980px;
@include at-least-width(1600px){
// a wide screen device with width >= 1600px
}
@include until-width(979px){
// phones and tablets (width <= 979px)
}
@include if-device(tablet){
// tablet (min-width 768px and max width 979px)
}
@include if-device(phone-tablet){
// phone or tablet (max-width 979px)
}
@include if-device(phone){
// phone (max-width 767px)
}
box-shadow($params)
text-shadow($params)
Example:
.title{
@include box-shadow(2px 2px 2px 0 #000);
}
rem-font($font-size-px, $line-height-px:false)
: Converts to rem values + provides px values as fallback (unless disabled in config).
Line height is optional. Example:
.title{
@include rem-font(18px,24px);
}
opacity($opacity)
: Accepts values between 0 and 1. Converts to filter property for IE support.
Example:
.thumb{
@include opacity(0.5);
}
non-selectable
: Disables ability to select text from the element
Example:
.description{
@include non-selectable;
}
hide-text
: Hides text by setting large negative text-indent value with overflow hidden.
Example:
.logo{
@include hide-text;
}
inline-block
: Converts element to inline block. Converts to inline as fallback for older IE browsers which do not support inline-block property.
Example:
.name{
@include inline-block;
}
clearfix
: Clears float using the before and after pseudo classes as table.
Example:
.element{
@include clearfix;
}
border-box
: Applies border-box box model to element.
Example:
.tile{
@include border-box;
}
ma
or mar-auto
: Auto value for left and right margin. (margin-left:auto; margin-right:auto;)
ml-a
or ml-auto
: auto
value for left margin property
mr-a
or mr-auto
: auto
value for right margin property
Specify values of margins to be generated in variable $scu-margins
and the library will automatically generate different cases based on these.
$scu-margins: (0 5 10 15 20)
Properties available are (where X
is one of the values passed in $scu-margins
mar-X
: Margin X. Eg: mar-5 is margin: 5px;
mt-X
: Top Margin. Eg: mt-10 is margin-top: 10px;
mb-X
: Bottom Margin. Eg: mb-10 is margin-bottom: 10px;
ml-X
: Left Margin. Eg: ml-10 is margin-left: 10px;
mr-X
: Right Margin. Eg: mr-10 is margin-right: 10px;
mv-X
: Vertical Margin. Eg: mv-5 is margin-top: 5px; margin-bottom: 5px;
mh-X
: Horizontal Margin. Eg: mh-5 is margin-left: 5px; margin-right: 5px;
Padding classes are also auto generated just like the margin classes.
pad-X
: Padding X. Eg: pad-5 is padding: 5px;
pt-X
: Top Padding. Eg: pt-10 is padding-top: 10px;
pb-X
: Bottom Padding. Eg: pb-10 is padding-bottom: 10px;
pl-X
: Left Padding. Eg: pl-10 is padding-left: 10px;
pr-X
: Right Padding. Eg: pr-10 is padding-right: 10px;
pv-X
: Vertical Padding. Eg: pv-5 is padding-top: 5px; padding-bottom: 5px;
ph-X
: Horizontal Padding. Eg: ph-5 is padding-left: 5px; padding-right: 5px;
All of these utility classes can be used with Device prefix technique. For example:
<div class="pad-40 align-center phn-pad-20 phn-pt-10 phn-align-left">Content</div>
This div will have 40px
padding in desktop and 20px
padding in phones. Additionally we have further changes the top padding to 10px
in phone.
Text align will be center
in desktop and left
in phone.
By default all of the css properties defined in the utility classes have !important
attribute to ensure that the classes work as expected by overiding values for the element.
This can be disabled with these variable:
$scu-use-important: true; // For all classes. Default value is true
$scu-paddings-use-important: true; // For auto generated paddings
$scu-margins-use-important: true; // For auto generated margins
Default Global and device prefixes can be changed with these variables:
$scu-prefix: "";
$scu-prefix-tablet: "tab-";
$scu-prefix-phone-tablet: "phn-tab-";
$scu-prefix-phone: "phn-";
The classes to be generated can be specified in variables $config-paddings
and $config-margins
. The default values are:
$scu-paddings: (0 5 10 15 20 25 30);
$scu-margins: (0 5 10 15 20 25 30);
You can even specify different values for vertical and horizontal classes. (Global as well as media cases)
Check the config.scss
file for all other config options and examples.
These classes are meant to be used only for making minor changes in elements. Default values should always be specified in the css class or id of the element.
If you have a patch, fork my repo and send me a pull request. Bugs can be reported in Issues section.
The MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.