search
top

Web Design: How To Make 3D Buttons in HTML

I’ve long enjoyed the Windows Classic theme. On the old gray taskbar, one can pin icons of favorite programs. On hover, borders appear: light on top and left, dark on bottom and right. When clicked, the light and dark flip, and the content inside, either a small image or text, move down and to the side by 1px. This gives the appearance of a button being depressed. It’s a very simple effect that seems to have been forgotten in this world of Web 2.0 we live in, so I’ve decided to try and replicate it myself for the navigation bar of my site.

You might ask, why not use the button or input tags? The problem with those is lack of customization options. While it might be a bit more code to build your buttons from scratch, you have a much wider range of options after they are finished. With the advent of HTML 5, you can even use this method to create curved buttons without using bandwidth-consuming images, though this tutorial doesn’t cover that specifically.

First thing, create your HTML document. For this tutorial, I’m going to set up a very simple document, with a container that’s got a gray background, to make the bottom and top borders of the buttons easier to see. It’s important to play around with colors. Sometimes the area beside a button is a color that makes the border hard to recognize, which robs from the effect.

<html>

<head>
<link rel=”stylesheet” href=”style.css”>
</head>

<body>
<div style=”width:206px; background:gray;”>
<br>
<br>
</div>
</body>

</html>

 

Inside your initial div container or inside your page create the button. Note, I’m going to make two buttons beside each other. This method easily allows creation of 1 or as many as you want beside each other, by adding more li’s inside your UL. First create div container and set the id to whatever you want. I use “nav”.

<div id=”nav”>
<ul>
<li><a href=”index.html”>Home
<li><a href=”schedule.html”>Schedule
</ul>
</div>

 

Next, create your css document. First, we enter the aspects that don’t change. Background color, height, width, etc.

#nav
{
background:#000;
overflow:hidden;
padding:0px; height:33px;
margin-bottom:0px;

#nav ul
{
padding:0px;
margin:0px;
font-size:0.95em;
}

#nav ul li
{
float:left;
display:block;
list-style-type:none;
align: center;
}

 

 

Next, in the same file, we set up the styling of links inside the id. Note, if you applied the settings below to the li itself, it works. That also has the benefit of letting you create the button without it being a link. However, if you do that, it causes problems for expanding sub menus. For those, it’s possible to limit the button effect to the initial menu, and have the expanding menu appear not as 3D. Applying the effects direction to the li tags, it’s not possible, at least that I know of, to do so.

Note: The first tag, for a, is broken with a space. In the first part, those are styles that don’t change. Only the borders, background, and margin change. The margin changes to move the text inside slightly, to add to the effect of the button.

#nav ul li a
{
font-size:15px;
height:23px;
width: 100px;
text-decoration:none;
color:#fff;
border-bottom:none;
text-align:center;
outline: 0; 

border: solid black 1px;
padding:7px 1px 1px 0px;
}

#nav ul li a:hover
{
background:#a37b2c;
border-top: solid #B88B32 1px;
border-left: solid #B88B32 1px;
border-right: solid #6B521D 1px;
border-bottom: solid #6B521D 1px;
padding:7px 1px 1px 0px;
}

#nav ul li a:active
{
background:#a37b2c;
border-top: solid #6B521D 1px;
border-left: solid #6B521D 1px;
border-right: solid #B88B32 1px;
border-bottom: solid #B88B32 1px;
padding:8px 0px 0px 1px;
}

 

When hover occurs, the borders appear. They are created individually because we want more than one color. When active (clicked), the bordered are flipped in regards to color. The margin also changes, moving the text down and to the right 1 px each. The finished product of our tutorial is:

Learn more the author of this post:

Andy Mercer
Andy Mercer is an undergraduate Civil Engineering student at Purdue University. Currently employed by ITaP (Information Technology at Purdue), he is interested in web design and programming. In his spare time he enjoys killing zombies and playing his 360.
top