Categories
CSS Web development

CSS Button Fill Effect on Hover

CSS Button Fill Effect on Hover

Demo:

*to see the CSS Button Fill Effect on the website click here.

To create the CSS Button Fill Effect on Hover follow the steps below:

  1. Add HTML
  2. Add CSS

Step1.

Add HTML

<button class="left">BUTTON</button>
<button class="up">BUTTON</button>

Step2.

Add CSS

Set the colour and the position of the background and elements:

body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

Style the buttons:

button {
  padding: 20px 20px;
  margin:20px;
  font-size: 25px;
  font-weight: bold;
  font-family: Tahoma, sans-serif;
  box-shadow:7px 7px rgba(0,0,0,0.5);
  transition: .3s ease;
  overflow: hidden;
  cursor: pointer;
}
.left {
  position: relative;
  border: 10px solid #2ec4b6;
  z-index:1;
}
.left:before {
  content:"";
  position: absolute;
  z-index:-1;
  top:0;
  left:0;
  height:100%;
  width:0;
  background-color: #2ec4b6;
  transition: .3s width ease;
}
.up {
  position: relative;
  border: 10px solid #f94144;
  z-index:1;
}
.up:before {
  content:"";
  position: absolute;
  z-index:-1;
  background-color: #f94144;
  width:100%;
  height:0;
  top:0;
  left:0;
  transition: height .3s ease;
}

Add transitions on hover:

button:hover {
  transform: translateY(7px) translateX(7px);
  box-shadow: 0 0 rgba(0,0,0,0.5); 
}
.left:hover {
  color: white;
}
.left:hover:before {
  width:100%;
}
.up:hover {
  color: white;
}
.up:hover:before {
  height: 100%;
}

Enjoy coding!

Categories
CSS Web development

CSS Shiny Button

CSS Shiny Button

We’ll create button and the shine effect using only pure CSS:

*animation opened in the Safari browser.
To see the animation on the website click here.

Demo:

To create the CSS Shiny Button follow the steps below and watch the video tutorial:

  1. Add HTML
  2. Add CSS

Let’s start with HTML:

Step 1.

Add HTML

<button class="button">Button</button>

Step 2.

Add CSS and CSS Animation

body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh; 
  background-color: #2b2d42;
}

.button {
  background: #8d99ae;
  color: white;
  font: 18px Georgia, sans-serif;
  line-height: 42px;
  padding: 1em 3em;
  position: relative;
  overflow: hidden;
   
}

.button::after {
  content: '';
  position: absolute;
  top: -50%;
  right: -50%;
  bottom: -50%;
  left: -50%;
  background: linear-gradient(to bottom, rgba(230, 175, 145, 0), rgba(255,255,255,0.5) 50%, rgba(229, 172, 142, 0)); 
  transform: rotateZ(60deg) translate(-5em, 7.5em);  
}

.button:hover::after, button:focus::after {
  animation: sheen 1.5s forwards;
}

@keyframes sheen {
  100% {
    transform: rotateZ(60deg) translate(1em, -9em);
  }
}

To see the live output visit: lenastanley.com

Watch also the video tutorial:

Enjoy coding!

Categories
CSS Web development

CSS Buttons

Button elements are not only good for user navigation but also a very important design element for any web page.

CSS Buttons

Learn how to style buttons with the CSS.

Basic button styling:

On the left side the default button, on the right styled with CSS:

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  background-color: #2a9d8f;
  border: none;
  color: black;
  padding: 20px 30px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 15px;
  cursor: pointer;
}
</style>
</head>
<body>

<button>DEFAULT BUTTON</button>
<button class="button">STYLED BUTTON</button>
</body>
</html>

Use the background-color property to change a colour:

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  background-color: #2a9d8f;
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}

.button2 {background-color: #e9c46a;}
.button3 {background-color: #e76f51;} 
.button4 {background-color: #f4a261;}
</style>
</head>
<body>

<button class="button">Green</button>
<button class="button button2">Yellow</button>
<button class="button button3">Red</button>
<button class="button button4">Orange</button>

</body>
</html>

Output:

You can change the size of a button too:

  1. Use the font-size property to change the font size of a button:
<!DOCTYPE html>
<html>
<head>
<style>
.button {
  background-color: #2a9d8f; 
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  margin: 4px 2px;
  cursor: pointer;
}

.button1 {font-size: 12px;}
.button2 {font-size: 14px;}
.button3 {font-size: 16px;}
.button4 {font-size: 22px;}
	
</style>
</head>
<body>


<button class="button button1">12px</button>
<button class="button button2">14px</button>
<button class="button button3">16px</button>
<button class="button button4">22px</button>

</body>
</html>

Output:

2. Use the padding property to change a padding of the button:

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  background-color: #2a9d8f; 
  border: none;
  color: white;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}

.button1 {padding: 10px;}
.button2 {padding: 12px 28px;}
.button3 {padding: 14px 40px;}
.button4 {padding: 32px;}

</style>
</head>
<body>

<button class="button button1">10px</button>
<button class="button button2">12px 28px</button>
<button class="button button3">14px 40px</button>
<button class="button button4">32px</button>

</body>
</html>

Output:

You can change the shape of the button by using the border-radius property:

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  background-color: #2a9d8f; 
  border: none;
  color: white;
  padding: 20px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}

.button1 {border-radius: 2px;}
.button3 {border-radius: 8px;}
.button4 {border-radius: 12px;}
.button5 {border-radius: 50%;}
</style>
</head>
<body>

<button class="button button1">2px</button>
<button class="button button3">8px</button>
<button class="button button4">12px</button>
<button class="button button5">50%</button>

</body>
</html>

Output:

Colored button borders. Use the border property to add a colored border to a button:

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  background-color: white; 
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}

.button1 {
  background-color: white; 
  color: black; 
  border: 2px solid #2a9d8f;
}

.button2 {
  background-color: white; 
  color: black; 
  border: 2px solid #e9c46a;
}

.button3 {
  background-color: white; 
  color: black; 
  border: 2px solid #e76f51;
}

.button4 {
  background-color: white;
  color: black;
  border: 2px solid #f4a261;
}

</style>
</head>
<body>

<button class="button button1">Green</button>
<button class="button button2">Yellow</button>
<button class="button button3">Red</button>
<button class="button button4">Orange</button>

</body>
</html>

Output:

Hoverable buttons. Use the :hover selector to change the style of a button when you move the mouse over it.

Tip: Use the transition-duration property to determine the speed of the “hover” effect:

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  background-color: white; 
  border: none;
  padding: 16px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  transition-duration: 0.4s;
  cursor: pointer;
}

.button1 {
  background-color: white; 
  color: black; 
  border: 2px solid #2a9d8f;
}

.button1:hover {
  background-color: #2a9d8f;
  color: white;
}

.button2 {
  background-color: white; 
  color: black; 
  border: 2px solid #e9c46a;
}

.button2:hover {
  background-color: #e9c46a;
  color: white;
}

.button3 {
  background-color: white; 
  color: black; 
  border: 2px solid #e76f51;
}

.button3:hover {
  background-color: #e76f51;
  color: white;
}

.button4 {
  background-color: white;
  color: black;
  border: 2px solid #f4a261;
}

.button4:hover {background-color: #f4a261;
   color: white;}

</style>
</head>
<body>

<button class="button button1">Green</button>
<button class="button button2">Blue</button>
<button class="button button3">Red</button>
<button class="button button4">Gray</button>


</body>
</html>

Output:

Shadow Buttons. Use the box-shadow property to add shadows to the button:

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  background-color: #2a9d8f; 
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
  transition-duration: 0.4s;
}

.button1 {
  box-shadow: 0 8px 15px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
}

.button2:hover {
  box-shadow: 5px 12px 15px 0 rgba(0,0,0,0.24),0 17px 50px 0 rgba(0,0,0,0.19);
}
</style>
</head>
<body>

<button class="button button1">Shadow Button</button>
<button class="button button2">Shadow on Hover</button>

</body>
</html>

Output:

Animated Buttons:

Add an arrow on hover:

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  display: inline-block;
  border-radius: 4px;
  background-color: #2a9d8f;
  border: none;
  color: #FFFFFF;
  text-align: center;
  font-size: 28px;
  padding: 20px;
  width: 200px;
  transition: all 0.5s;
  cursor: pointer;
  margin: 5px;
}

.button span {
  cursor: pointer;
  display: inline-block;
  position: relative;
  transition: 0.5s;
}

.button span:after {
  content: '\00bb';
  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>
</head>
<body>

<button class="button" style="vertical-align:middle"><span>Hover </span></button>

</body>
</html>

Output:

Add a “pressed” effect on click:

<!DOCTYPE html>
<html>
<head>
<style>
.button {
  display: inline-block;
  padding: 15px 25px;
  font-size: 24px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  outline: none;
  color: #fff;
  background-color: #2a9d8f;
  border: none;
  border-radius: 15px;
  box-shadow: 0 8px rgba(0,0,0,0.2);
}

.button:hover {background-color: #264653;}

.button:active {
  background-color: blue;
  box-shadow: 0 5px #666;
  transform: translateY(5px);
}
</style>
</head>
<body>

<button class="button">Click Me</button>

</body>
</html>

Output:

To see how to add to your buttons the shine effect click here.

Enjoy coding!