CSS Tips: How To Create Buttons Using CSS

cssbuttonsA long time back buttons were all the rage because it took some pretty nifty javascript knowledge to make them work. But that’s changed thanks to the power of CSS.

Buttons can be highly effective ways of highlighting links on your website, or displaying a “call to action”. In my experience people are often drawn to buttons more than standard links.

There are a few different ways you can use CSS to create buttons. The method that I tend to use most (and one of the simplest) is by using CSS to created class on an A tag.

The CSS Code:

a.button {
display: block;
border: 1px solid;
border-color: #aaa #000 #000 #aaa;
width: 8em;
background: #CCC;
padding: 2px;
text-decoration:none;
text-align:center;
}

a.button:hover {
position: relative;
top: 1px;
left: 1px;
border-color: #000 #aaa #aaa #000;
}

The HTML Code:

<a class=”button” href=”#”>Button</a>

Explanation:

First of all you will notice that there are 2 elements to the CSS.

The first is the actual styling for the A tag. This is the core design of the button, including the width, colors, shading etc. You will notice that I have given my elements a class called “button” by adding .button after the a in the CSS. This enables you to create multiple buttons of different styles using different class names (button1, button2, orangebutton, bigbutton, etc). In the code I have used i’ve set the background to light grey with a solid background that will be 8am wide. Virtually all this CSS is fully customizable. In fact, the only thing that you should keep intact is the “display:block” section.

The second section of the CSS refers to the hover effect of the button. What this does is tells the browser what to change after the mouse “hovers” over the element. Again, you will see i have connected it to the same class as the first section by giving it the .button class. The top / left elements will move the button slightly on hover and the border will change accordingly to give a hovered 3D effect. Hover over the demo button above to see how this works.

When you add the HTML code to your page, simply give it the relevant class (see code above) to match it all up and create CSS magic!

Want to fancy it up? Try adding rounded corners to the a.button section (ie. border:radius:4px;) to give a web2.0 type look and feel.

Helpful Links:

Webcredible (page includes CSS buttons)
Speckyboy CSS Styled Buttons

Share This:

DIV Tags: 2 Column Template Tutorial

Yesterday I posted an article introducing some really handy DIV tag style features. Today I wanted to take that a step further and use those styles to build a very simple website frame.

The frame we’re going to build is going to have a 5 DIVs initially, with more added at the end to style the frame. I am going to build a fixed width template set to 480px wide, centered with a 1 pixel black border.

The key DIV styles that we will be using in this example are:

  • Float
  • Border
  • Padding
  • Margin
  • Background
  • Width
  • Height

Step 1: The Header

There are a few different ways you can build a basic site template. I personally like to start with logic, which in this case is the top. So we want to code in the header, keeping in mind that we need to include things like padding.

<div style=”width: 480px; height: 50px; border: 1px solid #000000; margin: 0pt auto;”>
</div>

The result:

Notice I also included a fixed height for the header of 50 pixels.

Step 2: The Container

Before we can add the main content and sidebar areas we need to add the container. This will be a DIV that is not viewable to the user in the end product (in this example), however I am going to make it viewable now and then remove it at the end so you can see the result/purpose. I have put the newly added code in red.

<div style=”width: 480px; height: 50px; border: 1px solid #000000; margin: 0pt auto;”>
</div>
<div style=”width: 480px; border: 1px solid #000000; margin: 2px auto;”>
</div>

The result:

You’ll notice that I changed the margin for this new DIV. By adding the 2px before and after the “auto” it added a 2 pixel gap between the container and the header. I also did not include any “height” styling, which has resulted in the DIV looking flat. This will change.

Step 3: The Main Content and Sidebar

Next we want to add the main content area and the sidebar to the frame. The code for these will go INSIDE the container DIV tags. I also added an extra DIV in there (hightlighted in blue) that closes off the 2 new DIVs and ensures when we load the footer that it loads without any overflow from the previous DIVs.

<div style=”width: 480px; height: 50px; border: 1px solid #000000; margin: 0pt auto;”>
</div>
<div style=”width: 480px; border: 1px solid #000000; margin: 2px auto;”>
<div style=”width: 376px; height: 100px; float: left; border: 1px solid #000000;”>
</div>
<div style=”width: 100px;
height: 100px; float: right; border: 1px solid #000000;”>
</div>

<div style=”clear: both;”></div>

</div>

The result:

As you can see, the structure is now starting to take shape.

Step 3: The Footer

The footer is much like the header, and is a basic DIV that loads underneath the current structure. One piece of extra code we need to add to the footer is the “clear” attribute, which tells the code to stop all the current tags and start from this location. By adding it to the footer, we’re able to ensure the main content and sidebars don’t flow over into the footer content. Previously I had this code in it’s own div. What we’re going to do is take the previously highlighted blue code and add that to the footer.

<div style=”width: 480px; height: 50px; border: 1px solid #000000; margin: 0pt auto;”>
</div>
<div style=”width: 480px; border: 1px solid #000000; margin: 2px auto 2px;”>
<div style=”width: 376px; height: 100px; float: left; border: 1px solid #000000;”>
</div>
<div style=”width: 100px; height: 100px; float: right; border: 1px solid #000000;”>
</div>
<div style=”clear: both;”>
</div>
</div>
<div style=”width: 480px; height: 25px; border: 1px solid #000000; margin: 2px auto;”>
</div>

The result:

Step 4: Final Styling

The site is taking shape. What we need to do now is add some extra styling. In particularly, we want to:

  • Remove the border from the container
  • Add 4 new DIVs to add padding (optional)
  • Colour the background of the Header (blue), sidebar (yellow) and footer (blue)
  • Adjust the width of the main content to allow spacing between it and the sidebar
  • Add basic text to highlight each area.

<div style=”background: #000066; width: 480px; height: 50px; border: 1px solid #000000; margin: 0pt auto;”>
<div style=”width: 460px; padding: 10px;”>
<strong>HEADER</strong>
</div>

</div>
<div style=”width: 480px; margin: 2px auto 2px;”>
<div style=”width: 373px; height: 100px; float: left; border: 1px solid #000000;”>
<div style=”width: 453px; padding: 10px;”>

<strong>MAIN CONTENT AREA</strong>
</div>
</div>
<div style=”background: #FFFF99; width: 100px; height: 100px; float: right; border: 1px solid #000000;”>
<div style=”width: 80px; padding: 10px;”>
<strong>SIDEBAR</strong>
</div>
</div>
<div style=”clear: both;”>
</div>
</div>
<div style=”background: #000066; width: 480px; height: 25px; border: 1px solid #000000; margin: 2px auto;”>
<div style=”width: 460px; padding: 10px;”>
<strong>FOOTER</strong>
</div>
</div>

The result:

HEADER

MAIN CONTENT AREA

SIDEBAR

FOOTER

There you have it. A relatively simple, straight foward template build 100% using CSS.

Next article I will cover bringing images into the DIV as backgrounds and adding basic content.

If you’re wanting to learn more, we strongly recommend the Web Design Mastery Course.

Web Design Mastery is a complete Internet Marketers Reference Guide. Not only will you learn how to design a professional website, but you’ll also learn in the easiest possible fashion.

It is a fantastic product that will teach you all you need to know about Web Design.

Share This:

Beginners Guide to building a CSS Website – Videos #6 and #7

After a lengthy hiatus, we are back with 2 new videos in our beginners guide to building your own CSS website. In the latest 2 videos we show you how to use CSS driven image-bullet menus using the UL and LI functions, and also show you how to pull your template apart and re-build it using individual PHP files and the very handy PHP Require statement.

The videos:

CSS Tutorial to build your own CSS website – Part 6

CSS Tutorial to build your own CSS website – Part 7

You can also find our videos on YouTube at: http://www.youtube.com/user/trueblue55

Share This:

CSS Website Tutorial – # 5 Uploaded.

Today I uploaded part 5 of the video series teaching how to build a CSS website using nothing more than Notepad. In today’s video I gave an introduction to Styles and Formatting, and how they apply to CSS websites. Primarily todays video focusses on heading tags and setting styles withing the CSS stylesheet. In the next few videos we will be greatly enhancing the styles and bringing in more CSS styling options.

To view todays video, click the thumbnail in the right menu, or click here. You can also view the videos on youtube (if you have issues viewing them on here) by going to my Youtube page.

Share This:

3 Part Guide To Building A CSS Website

Over the last few years I have been approached many times asking for tips on how to build custom websites using up to date CSS build techniques.

CSS, or “Custom Style Sheet” is essentially a way to build websites that are quicker to load, easier to work with and compatible with more web browsers. Unlike original HTML which used clumsy tables and hard coded formatting, CSS is more fluid, and much much more powerful.

The problem is, those new to web design often turn to low quality web-design software to help them with their sites. Many of these still use the old style HTML, so the sites they build, while good looking and serving their use are not fully compatible with the search engines, and therefore seriously a major issue.
Continue reading

Share This: