Foreword

How To...

The following tutorials will walk you through creating several effects using techniques that will combine the HTML, JavaScript and CSS you have studied in the past lessons to create useful effects and tools.

This is where all of the study and practice culminate to show you what the possiblities are to produce some dazzling eye-candy that catch the attention of the visitors to the sites you will be creating.

Now more than ever, the presentation of the material and how users interact with it, become just as important as the content and the subject matter on the website. By becoming versed with basic design fundamentals and elements, combined with the working knowledge of HTML, CSS and JavaScript, one is armed with tools to create fun and effective interactive designs that capture the attention and promote interaction.

 








 







How To... Animate Buttons



Learn how to animate your buttons using CSS and add simple little effects that bring your pages alive.


Animated Buttons

Example

Add a "pressed" effect on click:

<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="images/style.css" title="style.css" media="">

<style>
.pressed {
display: inline-block;
padding: 15px 25px;
font-size: 24px;
cursor: pointer;
text-align: center;
text-decoration: none;
outline: none;
color: #fff;
background-color: #4CAF50;
border: none;
border-radius: 15px;
box-shadow: 0 9px #999;
}
.pressed:hover {
background-color: #3e8e41
}
.pressed:active {
background-color: #3e8e41;
box-shadow: 0 5px #666;
transform: translateY(4px);
}
</style>

<div class="padding-left padding-16 white">
<button style="margin: 5px; padding: 20px; width: 180px; font-size: 28px;" class="pressed">
<span>Click</span></button></div>
Try it Yourself »

Example

Add an arrow on hover:

<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="images/style.css" title="style.css" media="">
<style>
.button {
display: inline-block;
border-radius: 4px;
background-color: #f4511e;
border: none;
color: #FFFFFF;
text-align: center;
font-size: 28px;
padding: 20px;
width: 180px;
transition: all 0.5s;
cursor: pointer;
margin: 5px;
}
.button span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}
.button span:after {
content: '»';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
}
.button:hover span {
padding-right: 25px;
}
.button:hover span:after {
opacity: 1;
right: 0;
}
</style>

<div class="padding-left padding-16 white"><button style="vertical-align: middle;" class="button">
<span>Hover </span></button></div>
Try it Yourself »

Example

Add a "ripple" effect on click:

<div class="padding-left padding-16 white">
<button style="margin: 5px; padding: 20px; width: 180px; font-size: 28px;" class="btn ripple">
<span>Click </span></button></div>
Try it Yourself »

Go to our CSS Buttons Tutorial to learn more about how to style buttons.


 







How To... Full Screen Overlay Navigation


Learn how to create a full screen overlay navigation menu.

Choose the speed of how fast the menu transitions in and out, or try different levels of opacity to enhance the effect.


Click on the buttons below to see how it works:

×
×

Create a Full screen Overlay Navigation

Step 1) Add HTML:

Example

<!-- The overlay -->
<div id="myNav" class="overlay">

  <!-- Button to close the overlay navigation -->
  <a href="javascript:void(0)" class="closebtn" onclick="closeNav()" >&times;</a>

  <!-- Overlay content -->
  <div class="overlay-content">
    <a href="#">About</a>
    <a href="#">Services</a>
    <a href="#">Clients</a>
    <a href="#">Contact</a>
 </div>

</div>

<!-- Use any element to open/show the overlay navigation menu -->
<span onclick="openNav()">open</span>

Step 2) Add CSS:

Example

/* The Overlay (background) */
.overlay {
    /* Height & width depends on how you want to reveal the overlay (see JS below) */   
    height: 100%;
    width: 0;
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    left: 0;
    top: 0;
   background-color: rgb(0,0,0); /* Black fallback color */
   background-color: rgba(0,0,0, 0.9); /* Black w/opacity */
   overflow-x: hidden; /* Disable horizontal scroll */
   transition: 0.5s; /* 0.5 second transition effect to slide in or slide down the overlay (height or width, depending on reveal) */
}

/* Position the content inside the overlay */
.overlay-content {
    position: relative;
    top: 25%; /* 25% from the top */
    width: 100%; /* 100% width */
    text-align: center; /* Centered text/links */
    margin-top: 30px; /* 30px top margin to avoid conflict with the close button on smaller screens */
}

/* The navigation links inside the overlay */
.overlay a {
   padding: 8px;
   text-decoration: none;
   font-size: 36px;
   color: #818181;
   display: block; /* Display block instead of inline */
   transition: 0.3s;/* Transition effects on hover color) */
}

/* When you mouse over the navigation links, change their color */
.overlay a:hover, .overlay a:focus {
    color: #f1f1f1;
}

/* Position the close button (top right corner) */
.closebtn {
    position: absolute;
    top: 20px;
    right: 45px;
    font-size: 60px !important; /* Override the font-size specified earlier (36px) for all navigation links */
}

/* When the height of the screen is less than 450 pixels, change the font-size of the links and position the close button again, so they don't overlap */
@media screen and (max-height: 450px) {
    .overlay a {font-size: 20px}
    .closebtn {
        font-size: 40px !important;
        top: 15px;
        right: 35px;
    }
}

Step 3) Add JavaScript:

The example below slides in the overlay navigation menu from left to right (0 to 100% width), when it is triggered:

Example

/* Open when someone clicks on the span element */
function openNav() {
    document.getElementById("myNav").style.width = "100%";
}

/* Close when someone clicks on the "x" symbol inside the overlay */
function closeNav() {
    document.getElementById("myNav").style.width = "0%";
}
Try it Yourself »

The example below slides in the overlay navigation menu downwards from the top (0 to 100% height).

Note: In this example, note that the CSS is slightly different from the one above (default height is now 0, width is 100% and overflow-y is hidden (disable vertical scroll, except for small screens)):

Example

/* Open */
function openNav() {
    document.getElementById("myNav").style.height = "100%";
}

/* Close */
function closeNav() {
    document.getElementById("myNav").style.height = "0%";
}
Try it Yourself »

 







How To... Menu Icon


Learn how to create an animated menu icon with CSS that will transform from a menu icon to a close button.


How To Create a Menu Icon

If you are not using an icon library, you can create a basic menu icon with CSS:

Menu Icon:

Animated Menu Icon (click on it):


Step 1) Add HTML:

Example

<div class="barX></div>
<div class="barX></div>
<div class="barX></div>
(These are the 3 bars that will create the icon 1-3)
Step 2) Add CSS:

Example

barX {
    width: 35px;
    height: 5px;
    background-color: black;
    margin: 6px 0;
}

This is where the appearence of the bars gets defined

Example Explained

The width and the height property specifies the width and height of each bar.

We have added a black background-color, and the top and bottom margin is used to create some distance between each bar.


Animated Icon

Use CSS and JavaScript to change the menu icon to a "cancel/remove" icon when it is clicked on:

Step 1) Add HTML:

Example

<div class="container" onclick="myFunction(this)">
  <div class="bar1"></div>
  <div class="bar2"></div>
  <div class="bar3"></div>
</div>
Step 2) Add CSS:

Example

.container {
    display: inline-block;
    cursor: pointer;
}

.bar1, .bar2, .bar3 {
    width: 35px;
    height: 5px;
    background-color: #333;
    margin: 6px 0;
    transition: 0.4s;
}

/* Rotate first bar */
.change .bar1 {
    -webkit-transform: rotate(-45deg) translate(-9px, 6px) ;
    transform: rotate(-45deg) translate(-9px, 6px) ;
}

/* Fade out the second bar */
.change .bar2 {
    opacity: 0;
}

/* Rotate last bar */
.change .bar3 {
    -webkit-transform: rotate(45deg) translate(-8px, -8px) ;
    transform: rotate(45deg) translate(-8px, -8px) ;
}
Step 3) Add JavaScript:

Example

function myFunction(x) {
    x.classList.toggle("change");
}
Try it Yourself »

Example Explained

HTML & CSS: You will use the same styles as before, only this time, wrapping a container element around each <div> element and then specifying a class name for each.

The container element is used to show a pointer symbol when the user moves the mouse over the divs (bars). When it is clicked on, it will execute a JavaScript function that adds a new class name to it, which will change the styles of each horizontal bar: the first and the last bar transform and rotated to create the letter "x". The bar in the middle fades out and becomes invisible.