MaterializeCSS is a CSS and Javascript based front-end responsive framework, derived from Google's Material Design. It is based entirely on Google's Material Design guidelines and serves as a boilerplate in order to use material design in a better and fast way. It has some predefined plugins such as Scrollspy, Scrollfire, lightbox, parallax and much more.
Version | Release Date |
---|---|
0.93.0 | 2014-12-19 |
0.94.0 | 2015-12-30 |
0.95.0 | 2015-01-17 |
0.96.0 | 2015-04-01 |
0.97.0 | 2015-07-02 |
0.97.7 | 2016-07-23 |
0.97.8 | 2016-10-30 |
0.98.0 | 2017-01-25 |
0.98.1 | 2017-03-21 |
There are two ways to use MaterializeCSS, either you can download the files on your system or use the files from CDN (Content Delivery Network).
Download files
npm install materialize-css
bower install materialize
Include From CDN
Include minifed CSS in the head section:
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/css/materialize.min.css">
Include Javascript file in the Body section, just before the closing body tag.
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/js/materialize.min.js"></script>
This section is only relevant if you work with the Sass version of Materialize.
First, you need to install Sass in your working directory:
gem install sass
When you have Sass installed on your project and you want to update your output .css file, you need to use the following command:
sass sass/materialize.scss public/style.css
NOTE: the second parameter sass/materialize.scss is the path to your .scss file, and the last parameter sass/style.css is the path to your output folder when the file .css file is located.
If you want to avoid this command every time when you do a change, you can run a watch command:
sass --watch sass/sass:public/stylesheets
NOTE: this command watches all Sass files in the scss directory for changes and then update the style file into our public directory.
Once you've downloaded the files, extract your them into your designated directory.
You'll notice that there are two sets of the files. The min
means that the file is "compressed" to reduce load times. These minified files are usually used in production while it is better to use the unminified files during development.
After extracting, your directory's file structure should look like:
MyWebsite/
|--css/
| |--materialize.css
|
|--fonts/
| |--roboto/
|
|--js/
| |--materialize.js
|
|--index.html
Example MaterializeCSS HTML page:
<!DOCTYPE html>
<html>
<head>
<!--Import Google Icon Font-->
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/materialize.min.js"></script>
</body>
</html>
These are the simplest starter pages with a Header, Call-to-Action, and Icon Features.
Starter Template | Parallax Template |
---|---|
Demo or Download | Demo or Download |
There are many ways to use MaterializeCSS framework.
Few things to keep in mind before going to installation
You can use any of the following methods:
Each has its own advantages and disadvantages.
Just add this to index.html
and you are good to go .
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/css/materialize.min.css">
<!-- We need jquery first -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/js/materialize.min.js"></script>
Add it as an asset in your project. This helps in not depending on internet when building and running locally.
Extract them
Copy materialize.min.css
, jquery-3.2.1.min.js
and materialize.min.js
in your assets folder
add them to index.html
<link rel="stylesheet" href="./assets/materialize.min.css" >
<script src="./assets/jquery-3.2.1.min.js"></script>
<script src="./assets/materialize.min.js"></script>
In this method we directly include the files to our angular build. I am assuming the angular project is built with @angular/cli
for simplicity.
Do
npm install materialize-css --save
npm install jquery --save
This is same as downloading CSS files, but we dont need to add them in our repository.
Add the following to .angular-cli.json
:
"styles": [
"../node_modules/materialize-css/dist/css/materialize.css",
"styles.scss"
]
...
"scripts":[
"../node_modules/jquery/dist/jquery.js",
"../node_modules/materialize-css/dist/js/materialize.js"
]
Download source with SCSS version
Do this if you want to take advantage of SCSS
to change default behavior of the library. Otherwise you can still use previous method and use SCSS along side.
Add them to a folder outside src
. May be create a folder materialize-src
as sibling to src
and paste the contents there. We are doing this because npm install of materialize-css doesn't give us scss version. (Correct me if I am wrong )
Install jquery
npm install jquery --save
Add them to your .angular-cli.json
"styles": [
"../materialize-src/sass/materialize.scss",
"styles.scss"
],
"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../materialize-src/js/bin/materialize.min.js"
],
The above all installation methods provide full functionality with materialize and no need to further install anything to work in angular. Take any example and just use the appropriate HTML structure inside the component part of angular and you are good to go.
In some instances you might need to tinker with javascript and for that we need to use jQuery. Instead of that we can use the angular wrapper developer at angular2-materialize. I developed a full functional site using angular and materialize and never felt a need for that.
If you still believe you need it . You can install as follows :
Install materialize with any of the above mentioned ways
Install angular2-materialize
npm install angular2-materilize --save
Add in angular app.module.ts
import { MaterializeModule } from "angular2-materialize";
@NgModule({
imports: [
//...
MaterializeModule,
],
//...
})
Here is an example of a basic page using the Materialize CSS framework which incorporates the grid system and materialboxed
.
<!DOCTYPE html>
<html>
<head>
<title>Materializecss Example webpage</title>
<!--Import Google Icon Font-->
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/css/materialize.min.css" media="screen,projection"/>
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<div class="container">
<div class="row">
<div class="col s12"><h3>MATERIALIZECSS EXAMPLE</h3><h4>A simple website just to show how an element is used.</h4></div>
<div class="col s12 m6 l3">
<img class="materialboxed" width="100%" height="220" src="https://upload.wikimedia.org/wikipedia/commons/7/76/Katun_nature_reserve.jpg">
<h4>Katun Nature Reserve</h4>
<p><i>Lovely Place</i></p>
</div>
<div class="col s12 m6 l3">
<img class="materialboxed" width="100%" height="220" src="https://upload.wikimedia.org/wikipedia/commons/4/4b/Computer_art_4.png">
<h4>Art</h4>
<p><i>Simple & Attractive</i></p>
</div>
<div class="col s12 m6 l3">
<img class="materialboxed" width="100%" height="220" src="https://c1.staticflickr.com/9/8715/16947318656_4c6cbc3091_b.jpg">
<h4>Food</h4>
<p><i>For any occasion</i></p>
</div>
<div class="col s12 m6 l3">
<img class="materialboxed" width="100%" height="220" src="https://c1.staticflickr.com/7/6179/6217102314_350be5e843.jpg">
<h4>Steve Jobs</h4>
<p><i>Inspiration</i></p>
</div>
<div class="col s12"><h5>Comment your suggestion</h5></div>
</div>
</div>
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/js/materialize.min.js"></script>
<script>
$(document).ready(function(){
$('.materialboxed').materialbox();
});
</script>
</body>