Baseguide is a lightweight and robust CSS framework powered by Sass. It brings together all essential base components in a small yet powerful package.
Features
- Flexible and extendable breakpoint system
- Dynamic flexbox grid system with float fallback
- CSS-only custom form controls
- Consistent vertical rhythm and modular scale
- Responsive and scalable components
Getting started
Install with npm
npm install baseguide
Clone with git
git clone https://github.com/slavanga/baseguide
Download
[Download the latest release] (https://github.com/slavanga/baseguide/archive/master.zip)
Setup
Default variables can be changed before importing Baseguide. Take a look at the [_settings.scss] (https://github.com/slavanga/baseguide/blob/master/scss/baseguide/_settings.scss) file to get an overview of all variables.
$button-bg: #bada55;
@import 'baseguide';
The included gulpfile takes care of compiling, optimizing and minifying your assets. Running the following command will install all dependencies and start a local server using browsersync.
npm install && gulp serve
Grid
The grid framework is based on the [Bootstrap grid system] (http://getbootstrap.com/css/#grid).
Breakpoints
Breakpoints can easily be configured using the $mq-breakpoints
map. Note that the breakpoints have to be sorted from small to large.
The default configuration looks like this:
$mq-breakpoints: (
xs: 480px,
sm: 768px,
md: 992px,
lg: 1200px
);
Baseguide generates all the necessary grid and responsive visibility classes based on these breakpoints.
Media Queries
Media Queries are handled by [Sass MQ] (https://github.com/sass-mq/sass-mq).
@include mq(md) {
}
The snippet above compiles to the following CSS:
@media (min-width: 62em) {
}
Check out the [Sass MQ documentation] (http://sass-mq.github.io/sass-mq/#mixin-mq) for more details and advanced usage of media queries.
Legacy support
To support browsers without native media query support you could use [respond.js] (https://github.com/scottjehl/Respond).
A static solution without Javascript is possible by setting $mq-responsive
to false
. The code below generates an additional stylesheet where only styles in large (lg) media queries are included.
$mq-responsive: false;
$mq-static-breakpoint: lg;
@import 'main';
Include the generated CSS file after the rest of your styles to serve a fixed width layout to legacy browsers.
Gutters
The gutters are controlled by the $grid-gutter
variable. It can either be a global value across all breakpoints or a map with gutter values per breakpoint.
$grid-gutter: 60px;
$grid-gutter: (
xs: 20px,
md: 40px
);
Semantic / hybrid grid
The grid mixins can be used to create custom containers, rows and columns.
@include container($gutter, $width);
@include row($gutter);
@include column-base($gutter);
@include column($size, $columns);
@include column-push($size, $columns);
@include column-pull($size, $columns);
@include column-offset($size, $columns);
Tip: You can turn off the default columns output by setting $grid-columns-output
to false
.
The example below shows how to create a mobile first layout with five columns.
.col {
@include column-base;
}
.col-news-item {
@include mq(md) {
@include column(1, 5);
}
}
<div class="container">
<div class="row">
<article class="col col-news-item">News item</article>
<article class="col col-news-item">News item</article>
<article class="col col-news-item">News item</article>
<article class="col col-news-item">News item</article>
<article class="col col-news-item">News item</article>
</div>
</div>
Flexbox
The flexbox grid can be activated by setting $grid-flexbox
to true
. This is no kill switch for older browsers as the floats are kept in place for a basic fallback. Browsers that support flexbox and flex-wrap ([Support table] (http://caniuse.com/#search=flexbox)) will get these benefits:
- CSS-only equal height columns
- Easy vertical and horizontal alignment of columns
- Ordering and reversing of columns using CSS
Forms
Standard form controls
All form controls listed in $input-selector
get styled by default. The variable can be changed to a custom selector like .form-control
. This will allow you to selectively style form controls based on that selector.
Remember to reset the height of textareas if you choose a custom selector:
textarea.form-control {
height: auto;
}
Custom form controls
The custom forms component was designed with progressive enhancement in mind.
While the controls are functional in all browsers the following ones get the fully enhanced experience:
- Android 2.3+
- Chrome
- Firefox 35+
- IE 10+
- Mobile Safari 4+
- Safari 5.1+
- Opera 15+
You can set the variable $use-custom-forms
to false
to disable custom form styles in all browsers.
Browser support
Autoprefixer
Baseguide uses [Autoprefixer] (https://github.com/postcss/autoprefixer) to automatically add vendor prefixes to the CSS output. The browser support of the framework roughly corresponds to the autoprefixer settings:
browsers: [
'Android 2.3',
'Android >= 4',
'last 4 Chrome versions',
'Firefox ESR',
'Edge >= 12',
'IE >= 8',
'iOS >= 8',
'Safari >= 8',
'Opera >= 15'
]
Inspired By…