navbar in materialize css

Navbar in Materialize CSS

Learn about Navbar in Materialize CSS

Creating Navigation Bar

A navigation bar is a section of a graphical user interface intended to aid visitors in accessing information. Navigation bars are implemented in file browsers, web browsers and as a design element of some websites. Web Applications also require Navigation Bar in order to ease the access of the application. Materialize CSS provides a wide variety of Navigation bar types. Each Navbar option will be used in different scenarios.

Option 1: Left Aligned Logo and Right Aligned Links

All the components which have to be present on the website have to be added inside the body tag of the HTML file. All the style classes can be added in a separate file named style.css and can be linked to the HTML tag as we linked the Materialize CSS files. The first step in learning Navbar in Materialize CSS is to add Materialize CSS files in your working directory and call both CSS and JS files.

In order to add the Materialize Navbar in the HTML Structure we created, we refer to the Materialize CSS website and call in the Navbar coding and paste it into the body tag. You can get the navbar coding from Materialize CSS Website

navbar in materialize css
Navbar code

The Navbar code will create a navigation bar with left aligned logo slot and right aligned menu links. 

By default, Materialize CSS generates Navbar in Red color which can be changed by overriding the color class. In Materialize CSS it is easy to change the color of any container, just by referring the Materialize CSS Color documentation and adding the required color name we can change the color of any container. In this case, if it is required to change the color of the navbar to blue, just add class=”blue” inside the nav tag.

Navbar Blue Coding

Option 2: Right-Aligned Logo and Left-Aligned Links

In the above coding, if we change the class at two places we can achieve Right Aligned Logo and Left-Aligned Links. 

First, we should change the alignment inside <ul> from right to left. 

Second, we should add the class right next to the brand-logo class.

Output as follows

Option 3: Centering the Logo

We can align the logo to the center of Navbar easily by simply changing the alignment class right to center in the Option 2

The output will be as follows

Option 4: Active Navbar Items

Active Items in Navbar simply means that the highlighted menu item is the current page. In order to highlight a menu item as active, add class=”active” to the respective menu item <li>

The output will be as follows. Kindly note the darker shade of blue which relates to the active class.

Now that you know Navbar in Materialize CSS, Learn about Materialize CSS Simple Raised Button.

Materialize CSS Websites

First step in building Materialize CSS Websites and webpages

Learn the First step in building Materialize CSS Websites and webpages.

Download the Framework files from the Materialize CSS Framework Website, i.e., http://materializecss.com/getting-started.html. Extract the files and add the extracted files in the Project Directory. For this, you can create a new folder in Desktop.

Materialize CSS Websites
Download Method

On the contrary, without downloading the Framework files, we can add the respective CSS, JS and jQuery CDN in the Project HTML File. CDN link can be obtained from the link mentioned

Download the Framework files:

1. Go to the link: http://materializecss.com/getting-started.html

2. Download the Materialize CSS files

3. Once you have downloaded the zip file. You can extract to get the following files

Materialize CSS Project

The extracted folder contains CSS, JS and Fonts folder which contains respective files. Materialize CSS by default has Roboto font which can be changed as per requirement.

Creating HTML Pages

In order to work with CSS, JS and HTML files, we need a text editor, such as Brackets or Sublime Text Editor. It can be downloaded from their respective websites. 

After installing the Text Editor, you can add the Project Folder which contains the downloaded Materialize CSS Framework files and creates the index.html file in the folder

Traditional Method

Now in the index file, you can link the corresponding JS, CSS files. 

Project Folder

Note that we have used a CDN for the JQuery, you can also download the JQuery from the respective website, move it to the JS folder in our Project and link it as we have linked the Materialize CSS and JS files.

CDN Method

Instead of downloading the files from Materialize CSS we can also directly link the CDN hyperlinks for CSS and JS components which provided in the Materialize CSS website. This method is equal to that of the traditional method.

CDN Method

Now we are done with setting up the first Materialize CSS Project. Going further, we shall see how to create Navigation Bar, Menu, Creating Mega Menu, Cards, Buttons in the website/web pages. Learn about Materialize CSS Features

Materialize CSS - Features

Quick Read on Materialize CSS Features in 2021

Materialize CSS Features

Materialize CSS - Features
Materialize CSS Features

Introduction to Materialize CSS

•    Materialize CSS is one of the most trending and easy to use Web UI Framework
•    It is open source and can be used by all
•    Materialize is a UI component library created with CSS, JavaScript, and HTML
•    It can be easily understood and implemented after the training
•    It is augmented with several HTML, CSS, JS Components
•    It follows a grid system
•    It can be leveraged to create device-friendly webpages/websites
•    Adhere to modern web design principles like browser portability, device independence
•    Inspires Google Material Design Concepts

Materialize CSS Features

•    Responsive Designing 
•    Standard CSS
•    Provides Form Components such as Buttons, Check Boxes, Text Fields and many more based on Material Design
•    Provides Card Layouts, Modals, Tabs, Navigation, Bars, and many more
•    Requires jQuery
•    Open Source, i.e., Free to Use

What is Responsive Web Design?

•    Web Pages will act like water, i.e., adapt itself to the screen from which it is viewed as the water takes the shape of the container it is poured into
•    Materialize CSS is designed in such a way that all its CSS classes and components fit any screen size
•    Websites developed using Materialize CSS are fully compatible with PC, Tablets and Smart Phones    

Customizable

•    Materialize CSS provides very minimal and fully customizable CSS components
•    Materialize CSS is designed in such a way that all its default style classes can be overridden by our desired or required styles
•    It supports bright colours, shadows and animations
•    It is designed in such a way that all its colour and effects remain consistent across all the supported devices

Learn about the Materialize CSS Raised Button and Customization.

For more details about various courses, check out Ampersand Academy.

Materialize CSS Simple Raised Button Customization

Learn about Materialize CSS Simple Raised Button Customization.

Introduction:

Buttons are one of the most widely used elements in any of the HTML Frameworks. No wonder it is going to be different in Materialize CSS Framework. There are several types of buttons that are present in Materialize CSS Framework which includes Simple Button, Simply Raised Button, Flat Buttons, Floating Button, Fab Buttons, Disabled Buttons and much more. This tutorial will be brief about customizing a simple raised button and changing its style according to the need. 

Simple Button

In Materialize CSS it is easy to create a button. By simply adding “btn” class in <a> will produce a simple raised button with teal colour. Teal is the default colour that Materialize CSS Framework produces when no colour is specified. 

<a href="#" class="btn">Test</a>
Simple Raised Button

Changing Color in Simple Button

It is easy to change the colour of buttons in Materialize CSS Framework. By simply adding the colour name as prescribed in the Materialize CSS Framework Color Palette with the class will produce preferred colours. 

Link for Color Palette:

http://materializecss.com/color.html

Now in order to change the default Teal colour of the button to Dark, Red, we can add the class red darken-4 class inside the Class. This will produce a Simple Raised button with a Dark Red colour. 

<a href="#" class="btn red darken-4">Test</a>
Red Button

We can either darken the main colour by adding darken class next to the prime colour. Materialize CSS give 4 variations for darkening as well as for lightening and accent shades. You can play around and produce several colour variations according to the need. 

We can also apply a new colour that is not present in the Materialize CSS using CSS properties. For example, if I wish to add orange colour with hex code: #FF6347, the following method will help in adding custom colour to the button.

<a href="#" class="btn" style="background-color: #FF6347">Test</a>
Materialize CSS Simple Raised Button Customization
Custom Colour Button in Materialize CSS

In the above Orange Button, if you wish to change the text colour to Black, the coding is as follows:

<a href="#" class="btn" style="background-color: #FF6347; color:black">Test</a>
Simple Raised Button with Black Text

Changing Button Size

There is a default option in Materialize CSS Framework to increase the size of the button. By simply adding btn-large class next to btn class will increase the size of the button.

<a href="#" class="btn btn-large">Test</a> 
Button Large

Disabled Button

Materialize CSS provides an easy option to add a button disable property to a button. Simply adding a disabled class next to the btn class will create a Disabled Button. 

<a href="#" class="btn disabled">Test</a>
Button Disabled

Waves Effect

Wave is an external library that produces an ink ripple effect in button components. Materialize CSS provides a waves effect to buttons. The waves effect can be added to any button by simply adding the class waves-effect next to the btn class. This produces an ink ripple effect when a button is clicked. Furthermore, waves have several options which can be implemented in buttons. Let’s discuss everything in detail.

Simple Waves Effect

Waves-effect creates an ink wave effect in a button. The colour of the waves will be similar to that of the button colour. 

<a href="#" class="btn waves-effect">Test</a>

Waves Light

Waves-light class, when applied along with the Waves-effect, will produce ink waves in white colour. These effects can be utilized in various scenarios where the white tint is required. 

Waves Color

In Materialize CSS, there are several predefined waves colour that can be utilized in the button. Materialize CSS offers various Wave Colors such as White, Red, Yellow, Orange, Purple, Green, and Teal. These predefined waves colour can be directly called by adding respective classes such as waves-red, waves-green, etc.

<a href="#" class="btn waves-effect waves-red">Test</a>

Colour of the waves can be customized by creating new classes, for example, if you require brown waves effect you can use the following CSS

.waves-effect.waves-brown .waves-ripple {‘
 background-color: rgba(121, 85, 72, 0.65);
}
<a href="#" class="btn white black-text waves-effect waves-brown">Test</a>

Button with Icons

Materialize CSS provides an easy way to integrate icons into Buttons. In order to add icons to buttons, we need to add Google Material Icons CDN to the Website. After adding CDN, it is easy to call the icon in a button. We can change the icon as per our requirement by cross-referencing with the Google Material Icon list. The following coding will explain how icons are added to the button.

<a class="waves-effect waves-light btn"><i class="material-icons left">cloud</i>button</a>

You can also check the Materialize Card Animation Tutorial.

Extension and Operators in SASS

Extension and Operators in SASS. Learn and implement Extension and operators in SASS.

The extension is a feature in SASS / SCSS through which we can apply styles of one class to another just by calling the @extend in the subsequent class. Here’s the following example in which we have explained the classic use case of extending 

Create a class with the name paragraph1

.paragraph1{
    color: red;
    background: white; 
    &:hover{
        color: pink;
    }
}

Create another class with the name paragraph2 and inside it call the paragraph1 style with @extend function.

.paragraph2{
    @extend .paragraph1;
    &:hover{
        color: yellow;
    }
}

Operators in SASS / SCSS is similar to CSS operators. There are operator functions such as addition, subtraction, multiplication and division. 

How operators are used in CSS:

.paragraph1{
    width:  calc(80% - 40%);
}

How operators are used in SASS / SCSS: 

.paragraph1 {
    width: 80% - 40%;
}

There is no need to use the calc function. 

The basics of SASS / SCSS is over with the extend and operators. You can explore more with the learning in your projects.

Light and Dark Theme using Mixin

Light and Dark Theme using Mixin and implement in your web projects.

It is possible to switch between a dark and light theme using simple SCSS  / SASS without many code lines. We can leverage Mixin to achieve the change in light and dark themes. Following is the code for creating Mixin which can easily switch between light and dark themes. 

We will leverage two functions lighten and darken inside Mixin two achieve the functionality. Lighten function will help lighten the applied colour, and darken function will help darken the used colour. 

$primary-color: #000000;
$text-color: #3af80a;
$secondary-color: #432396;

@mixin theme($light-theme: true) {
    @if $light-theme{
        background: lighten($primary-color, 100%);
        color: darken ($text-color, 100%);
    }
}

Now create a class called light and apply it to the body tag. Inside the light class now include the theme mixin to enable the theme switch property.

.light{
    @include theme ($light-theme: true);
}

If the $light-theme is true, the HTML page will apply a light theme, the background colour will be light, and the text colour will be dark. If the $light-theme is false, the HTML page will apply a dark theme. 

.light{
    @include theme ($light-theme: false);
}

The above code will create a dark background and light text colour. In the next tutorial, we will learn Extension and Operators in SASS / SCSS.

Mixins in SASS

Learn Mixins in SASS and reutilize style

Mixins permit you to characterize styles that can be re-utilized all through your stylesheet. They make it simple to try not to utilize non-semantic classes like .float-left and to disperse assortments of libraries’ styles. 

Mixins are characterized utilizing the @mixin at-rule, which is composed @mixin <name> { … } or @mixin name(<arguments…>) { … }

Following is a simple example of using mixing to define content to centre.

@mixin flexCenter{

display: flex;

justify-content: center; 

align-items: center; 

}

Now just using @include to call the mixin will copy the entire style. The beauty is that it can be called n number of times inside the SCSS file.

.main {

@include flexCenter;

}

The SCSS compiles to the following CSS

.main {

display: flex;

justify-content: center; 

align-items: center; 

}

Here’s another classic example using arguments inside mixins to define the flex-direction. 

@mixin flexCenter($direction) {

flex-direction: $direction

}

To call the mixin with the argument, follow the example.

.main{

@include flexCenter(column);

}

The column parameter defined inside flexCenter mixin will specify the flex-direction to the column, and the following is equivalent CSS

.main {

display: flex;

justify-content: center; 

align-items: center; 

flex-direction: column

}

Learn to implement

Functions in SASS

Learn functions in sass. Create functions, call them and level up your SASS Skills.

Functions permit you to characterize complex operations on SassScript values that you can reuse all through your stylesheet. They make it simple to extract out standard formulae and practices in a decipherable manner. The function helps in computing calculations and return values in SASS / SCSS. 

Functions are characterized utilizing the @function at-rule, which is composed @function <name>(<arguments…>) { … }

Following is a simple demonstration of how we can implement a function in SASS / SCSS. Let’s define the variable font-weights to allocate a name to respective font-weight such as light, regular and bold.

$font-weights:(
    "light": 300,
    "regular": 400,
    "bold": 700
);

Next, we can define the function weight to integrate the font-weights class.

@function weight($weight-name){
    @return map-get($font-weights , $weight-name)
}

Now, we can directly leverage function by calling the function weight to define font-weight in CSS

.main{
     font-weight: weight(light);
}

The respective output CSS will be as follows:

.main{
    font-weight: 300;
}

In the next tutorial, we will be learning Mixins in SASS

partials in sass

Easily implement Partials in SASS in 2021

Learn Partials in SASS quickly in 5 mins and start implementing in your projects

Partial in SASS / SCSS is useful when the project files are enormous. Reusing or maintaining such huge SCSS files is cumbersome. Partial SCSS allows developers to split the variable, resets or page-wise SCSS separately and quickly embed them in the main SCSS. The main advantage of SASS is that partial SCSS files will not compile into new CSS files and therefore it becomes easier to manage. 

partials in sass
Partials in SASS

To make a particular SCSS a partial file, we can add an underscore before the file name and follow by .scss extension. For example, if we are to take variables of the main scss to a partial file, we can cut the variables and paste in a new scss file with the name _variables.scss and we can embed it using the import function in the main scss. 

SCSS file before the split of partial SCSS files: 

File name: main.scss

$primary-color: #d2d2d2;

$secondary-color: #322332;

$accent-color: #435434;

$text-color: #0000;

p{

color:$primary-color;

background-color: $secondary-color;

}

CSS Output

p{

color: #d2d2d2;

background-color: #322332;

}

Split variables to new SCSS files

File name: _variables.scss

$primary-color: #d2d2d2;

$secondary-color: #322332;

$accent-color: #435434;

$text-color: #0000;

File name: main.scss

@import './variables'; 

p{

color:$primary-color;

background-color: $secondary-color;

}

Please note: No need to call the filename with an extension scss, calling just the name of the file is sufficient

CSS Output

p{

color: #d2d2d2;

background-color: #322332;

}

In the next tutorials, we will learn how to create functions and call functions in SASS.

For more details about various courses, check out Ampersand Academy.

Nesting in SASS

Learn Nesting in SASS with easy guide and working examples

Nesting in SASS / SCSS is easy with the help of “&” to achieve the nesting. In SASS “&” behaves uniquely and it denotes the current selector.  The selector changes as we nest down.  If we want to define a division with a width of 80% and aligning to a centre with margin style, we use the following code.

.main{
    width:80%;
    margin: 0 auto;
}

Now if we want to apply the class inside main and with the name of main_new. The class main_new defines the style inside the main class. We can nest it with the following code.

.main{
    width:80%;
    margin:0 auto;
    &_new{
        font-size: 2em;
    }
}

The above SCSS will compile into the following CSS code. 

.main {
    width:80%;
    margin:0 auto;
}
.main_new{
    font-size: 2em;
}

To copy the SCSS expression string to the subclass, we can use “#{&}” to copy the entire main class expression to the following subclass. If we want to achieve the CSS as mentioned below, we can use the nesting with interpolation.

Desired CSS

.main{
    width:80%;
    margin:0 auto;
}

.main .main_new{
    font-size:2em;
}

Actual SCSS Code

.main{
    width:80%;
    margin:0 auto;
    #{&}_new{
        font-size: 2em;
    }
}

Successfully, you have learned nesting in SASS. In the next tutorial, we will be learning Partials in SASS, how to implement partials in your website project