Create CSS3 button with Pseudo elements

VIEW DEMO | DOWNLOAD

Pseudo elements or Pseudo Class, CSS pseudo-classes are used to add special effects to some selectors.

Hola, amigos. For the last month or so, I’ve been experimenting with the power of CSS pseudo-elements, specially when it comes to mixing them with buttons and that way recreating some great effects that were only possible to do with sprites, in the past.

In this tutorial, I’ll show you how to create buttons with a twist, using just one anchor tag per button and the great power of CSS.

The font used is ‘Open Sans’ by Steve Matteson.

Disclaimer:
I’ll not be using CSS vendor prefixes in this tutorial or else it would be crazy long, but you will find them in the downloadable files.

I avoided CSS transitions since, right now, Firefox is the only browser that supports them on pseudo-elements. Plus, I believe that these buttons work just fine without them.

Markup

The structure of all these buttons needs just one anchor tag for it to work, since we will be creating the other elements with the ::before pseudo-class.

1
2
3
<a href="#" class="a_demo_one">
     Click me!
</a>

EXAMPLE 1

cssbuttons_01

I think this is the easiest one, with a very regular CSS.

CSS

First of all, we will give the general style of the button, including its active state. It is important to notice the relative positioning, since it will help us later with the positioning of the ::before element:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
.a_demo_one {
    background-color:#ba2323;
    padding:10px;
    position:relative;
    font-family: 'Open Sans', sans-serif;
    font-size:12px;
    text-decoration:none;
    color:#fff;
    border: solid 1px #831212;
    background-image: linear-gradient(bottom, rgb(171,27,27) 0%, rgb(212,51,51) 100%);
    border-radius: 5px;
}
.a_demo_one:active {
    padding-bottom:9px;
    padding-left:10px;
    padding-right:10px;
    padding-top:11px;
    top:1px;
    background-image: linear-gradient(bottom, rgb(171,27,27) 100%, rgb(212,51,51) 0%);
}

Then, we create the gray container using the ::before pseudo-element. Absolute positioning makes our life easier to, believe it or not, position our element:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
.a_demo_one::before {
    background-color:#ccd0d5;
    content:"";
    display:block;
    position:absolute;
    width:100%;
    height:100%;
    padding:8px;
    left:-8px;
    top:-8px;
    z-index:-1;
    border-radius: 5px;
    box-shadow: inset 0px 1px 1px #909193, 0px 1px 0px #fff;
}

EXAMPLE 2

cssbuttons_02

This one is a little bit more complex because of the 3D’ish look. This button is outside of its ‘container’, but when you click it, it goes down:

CSS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
.a_demo_two {
    background-color:#6fba26;
    padding:10px;
    position:relative;
    font-family: 'Open Sans', sans-serif;
    font-size:12px;
    text-decoration:none;
    color:#fff;
    background-image: linear-gradient(bottom, rgb(100,170,30) 0%, rgb(129,212,51) 100%);
    box-shadow: inset 0px 1px 0px #b2f17f, 0px 6px 0px #3d6f0d;
    border-radius: 5px;
}
.a_demo_two:active {
    top:7px;
    background-image: linear-gradient(bottom, rgb(100,170,30) 100%, rgb(129,212,51) 0%);
    box-shadow: inset 0px 1px 0px #b2f17f, inset 0px -1px 0px #3d6f0d;
    color: #156785;
    text-shadow: 0px 1px 1px rgba(255,255,255,0.3);
    background: rgb(44,160,202);
}

And here’s the tricky part:

Since the position of the pseudo-element depends on its parent, once the parent moves down a few pixels, you have to move up the pseudo-element that same amount of pixels.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
.a_demo_two::before {
    background-color:#072239;
    content:"";
    display:block;
    position:absolute;
    width:100%;
    height:100%;
    padding-left:2px;
    padding-right:2px;
    padding-bottom:4px;
    left:-2px;
    top:5px;
    z-index:-1;
    border-radius: 6px;
    box-shadow: 0px 1px 0px #fff;
}
.a_demo_two:active::before {
    top:-2px;
}

EXAMPLE 3

cssbuttons_03

I think this one is my favorite since it was the first one I ever made this way and people seem to really like it. It is a divided button that “breaks” once you click it.

CSS

Again, the first thing we have to do is create the lighter part. In here, you’ll notice a right margin, this is in order to compensate for the width of the pseudo-element if you want to center the button. You don’t need it if that is not a problem for you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
.a_demo_three {
    background-color:#3bb3e0;
    font-family: 'Open Sans', sans-serif;
    font-size:12px;
    text-decoration:none;
    color:#fff;
    position:relative;
    padding:10px 20px;
    border-left:solid 1px #2ab7ec;
    margin-left:35px;
    background-image: linear-gradient(bottom, rgb(44,160,202) 0%, rgb(62,184,229) 100%);
    border-top-right-radius: 5px;
    border-bottom-right-radius: 5px;
    box-shadow: inset 0px 1px 0px #2ab7ec, 0px 5px 0px 0px #156785, 0px 10px 5px #999;
}
.a_demo_three:active {
    top:3px;
    background-image: linear-gradient(bottom, rgb(62,184,229) 0%, rgb(44,160,202) 100%);
    box-shadow: inset 0px 1px 0px #2ab7ec, 0px 2px 0px 0px #156785, 0px 5px 3px #999;
}

And then the pseudo-element’s CSS:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
.a_demo_three::before {
    content:"·";
    width:35px;
    max-height:29px;
    height:100%;
    position:absolute;
    display:block;
    padding-top:8px;
    top:0px;
    left:-36px;
    font-size:16px;
    font-weight:bold;
    color:#8fd1ea;
    text-shadow:1px 1px 0px #07526e;
    border-right:solid 1px #07526e;
    background-image: linear-gradient(bottom, rgb(10,94,125) 0%, rgb(14,139,184) 100%);
    border-top-left-radius: 5px;
    border-bottom-left-radius: 5px;
    box-shadow:inset 0px 1px 0px #2ab7ec, 0px 5px 0px 0px #032b3a, 0px 10px 5px #999 ;
}
.a_demo_three:active::before {
    top:-3px;
    box-shadow:inset 0px 1px 0px #2ab7ec, 0px 5px 0px 0px #032b3a, 1px 1px 0px 0px #044a64, 2px 2px 0px 0px #044a64, 2px 5px 0px 0px #044a64, 6px 4px 2px #0b698b, 0px 10px 5px #999 ;
}

EXAMPLE 4

cssbutton_04

This time, we will use the pseudo-element as a pointer, using one image as a background, though you can use some of those great icon fonts.

CSS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
.a_demo_four {
    background-color:#4b3f39;
    font-family: 'Open Sans', sans-serif;
    font-size:12px;
    text-decoration:none;
    color:#fff;
    position:relative;
    padding:10px 20px;
    padding-right:50px;
    background-image: linear-gradient(bottom, rgb(62,51,46) 0%, rgb(101,86,78) 100%);
    border-radius: 5px;
    box-shadow: inset 0px 1px 0px #9e8d84, 0px 5px 0px 0px #322620, 0px 10px 5px #999;
}
.a_demo_four:active {
    top:3px;
    background-image: linear-gradient(bottom, rgb(62,51,46) 100%, rgb(101,86,78) 0%);
    box-shadow: inset 0px 1px 0px #9e8d84, 0px 2px 0px 0px #322620, 0px 5px 3px #999;
}
.a_demo_four::before {
    background-color:#322620;
    background-image:url(../images/right_arrow.png);
    background-repeat:no-repeat;
    background-position:center center;
    content:"";
    width:20px;
    height:20px;
    position:absolute;
    right:15px;
    top:50%;
    margin-top:-9px;
    border-radius: 50%;
    box-shadow: inset 0px 1px 0px #19120f, 0px 1px 0px #827066;
}
.a_demo_four:active::before {
    top:50%;
    margin-top:-12px;
    box-shadow: inset 0px 1px 0px #827066, 0px 3px 0px #19120f, 0px 6px 3px #382e29;
}

EXAMPLE 5

cssbuttons_05

This example is a bit cheesy, I know, but you can use it in so many and really useful ways.

CSS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
.a_demo_five {
    background-color:#9827d3;
    width:150px;
    display:inline-block;
    font-family: 'Open Sans', sans-serif;
    font-size:12px;
    text-decoration:none;
    color:#fff;
    position:relative;
    margin-top:40px;
    padding-bottom:10px;
    padding-top:10px;
    background-image: linear-gradient(bottom, rgb(168,48,232) 100%, rgb(141,32,196) 0%);
    border-bottom-right-radius: 5px;
    border-bottom-left-radius: 5px;
    box-shadow: inset 0px 1px 0px #ca73f8, 0px 5px 0px 0px #6a1099, 0px 10px 5px #999;
}
.a_demo_five:active {
    top:3px;
    background-image: linear-gradient(bottom, rgb(168,48,232) 0%, rgb(141,32,196) 100%);
    box-shadow: inset 0px 4px 1px #7215a3, 0px 2px 0px 0px #6a1099, 0px 5px 3px #999;
}
.a_demo_five::before {
    background-color:#fff;
    background-image:url(../images/heart.gif);
    background-repeat:no-repeat;
    background-position:center center;
    border-left:solid 1px #CCC;
    border-top:solid 1px #CCC;
    border-right:solid 1px #CCC;
    content:"";
    width:148px;
    height:40px;
    position:absolute;
    top:-30px;
    left:0px;
    margin-top:-11px;
    z-index:-1;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
}
.a_demo_five:active::before {
    top: -33px;
    box-shadow: 0px 3px 0px #ccc;
}

IN THE END

And well, this is it, for now. Remember that these buttons are still kind of experimental, so not every browser supports them that well.

Thank you for reading this tutorial and I hope that you find it useful.

VIEW DEMO | DOWNLOAD

Original link: http://tympanus.net/codrops/2012/01/11/css-buttons-with-pseudo-elements/

40 Beautiful Free HTML5 & CSS3 Templates

1. HTML5 Theme
A minimal looking grey and pink design that comes packaged with an Ajax powered PHP contact form.

Info & Download | Demo
2. OWMX-1
A beautiful clean two column design that would be perfect for a blog.

Info & Download
3. DesignStudio
A grunge styled website that is suitable for a portfolio or a blog.

Info & Download | Demo
4. SilverBlog
A great looking clean blog template that has been also ported to WordPress.

Info & Download | Demo
5. Clean Red
A clean HTML5 powered template that could be used for a portfolio or blog. The download includes the original Photoshop PSD file.

Info & Download | Demo
6. CoffeeCols
A magazine style template that features rounded corners and comes packaged with an inner template too.

Info & Download | Demo
7. Design Company Website
A beautiful corporate style website that features its own gallery page. It also supports custom fonts.

Info & Download
8. Minimalism
A simple corporate style design that has beautiful typography.

Info & Download | Demo
9. Serenity
A one column template that features an image slider on the home page.

Info & Download | Demo
10. Vibrant Professional Web Design
A bright and colourful corporate style template.

Info & Download
11. DaFrontPage
A news style magazine template that has a 3 column layout.

Info & Download | Demo
12. High Five
A beautiful free template that could be used for a blog or portfolio website. The original Photoshop PSD file is included in the download file.

Info & Download | Demo
13. Business Project
A black and green corporate style template that features a jQuery slider on the home page.

Info & Download | Demo
14. Single-Page Portfolio
A fantastic single-page portfolio template that comes packaged with the original Photoshop PSD files.

Info & Download | Demo
15. Studio One
Another great template from CSS Heaven, this corporate style template features a jQuery slider on the home page and includes a portfolio section.

Info & Download | Demo
16. Memoir
A Japanese inspired free template that would be perfect for a personal blog.

Info & Download | Demo
17. Simple Style 7
A fixed width 5 page template that uses Google fonts.

Info & Download | Demo
18. Night Club
A well designed template that was created specifically for night clubs. The photoshop PSD file can be downloaded if you sign up to the TemplateMonster newsletter.

Info & Download | Demo
19. Small Business
A small business template that also includes an about and services page.

Info & Download | Demo
20. Cooking Site
A tremendous recipe template that has a featured post slider on the home page.

Info & Download | Demo
21. VividPhoto
A beautiful photography template from Pritesh Gupta that allows visitors to browse images at the bottom of the page.

Info & Download | Demo
22. Shinra
A fresh corporate style that uses Google fonts and comes with contact, gallery and portfolio templates.

Info & Download | Demo
23. One Page Portfolio
A simple backwards compatible one page portfolio template.

Info & Download | Demo
24. ArchiteXture
A simple 2 column template that would be suitable for a small business website.

Info & Download | Demo
25. ElegantPress
A clean template that’s packed full of features. It includes a jQuery slider on the home page, built in contact form, lightbox for images, jQuery gallery and a jQuery portfolio.

Info & Download | Demo
26. SocialStream
A useful template for social media fans that allows you to display a live stream of your Facebook or Twitter activity.

Info & Download | Demo
27. OnlineSolutions
A 3 column orange template that is suitable for a business website.

Info & Download | Demo
28. Touch The Future
An elegant free template design that includes a tutorial that explains how the theme was designed.

Info & Download | Demo
29. FreshIdeas
A simple black and yellow 2 column template.

Info & Download | Demo
30. Restaurant
Beautiful typography and a good looking jQuery slider on the home page make this a great template for a restaurant website.

Info & Download | Demo
31. HTML5 Admin Template
An advanced HTML5 admin template that can be used for creating a feature rich dashboard for your admin area.

Info & Download | Demo
32. HTML5 Admin
Another great HTML powered admin template that can be used as a template for your own project.

Info & Download | Demo
33. 52framework
Includes a simple HTML5 page, feature full HTML5 page and form, grid and CSS frameworks.

Info & Download | Demo
34. One-Page Template
A great looking blue one page template that uses jQuery to slide to different sections of the page.

Info & Download | Demo
35. Lifebook
A simple yet fun blogging template that features rounded corners.

Info & Download | Demo
36. PKE Meter
Create your own iPhone app website using this useful free template. The HTML5 code and graphical design are explained in full to help you understand the template better.

Info & Download | Demo
37. HTML5 Starter Pack
Contains photoshop designs, reusable CSS classes, javascript and more to help you create your own HTML5 powered website.

Info & Download
38. HTML5 template
A simple HTML template that comes in one column, two column and three column variations.

Info & Download | Demo
39. Nova
An HTML5 template that comes with 5 page templates, featured post slider, contact form and an image and video gallery.

Info & Download | Demo
40. Kroft
Includes 6 background images, 6 page templates, homepage slideshow and social media integration. The photoshop PSD file can also be downloaded.

Info & Download | Demo

HTML5: Background Generator

 

 

HTML5: Background Generator

 

 

Background Generator (BG) provides the ability to edit the background of any website in real-time! To give you an idea, the backgrounds of the Journal, Photos, Projects, and Labs sections of Mudcu.be were created using BG.

BG allows you to create fancy Web 3.0 backgrounds without getting dirty with Photoshop, GIMP, ect. The project includes a collection of textures (wood, rust, paper, concrete and so-on) which are combined with custom linear-gradients and colors to create a wide assortment of themes.

BG outputs valid CSS3 code, and also supports older browsers back to CSS1.  Supporting CSS1 is accomplished through the fallback of using of an embedded JPEG. Designers targeting newer browsers will also be happy; BG supports -moz-linear-gradient (for Firefox), -o-linear-gradient (for Opera) and -webkit-gradient (for Safari/Chrome) with multiple color-stops. Additionally, BG outputs DXImageTransform (Internet Explorer) code, as long as there are no more than two color-stops; IE can support multiple color-stops by using the fallback method (JPEG). Supporting browsers across the spectrum: IE, Firefox, Safari, Chrome, and Opera.

Please enjoy, and if you find it useful, post the website you designed here!

Ref: http://mudcu.be/journal/2011/03/html5-background-generator/

Ping your blog, website, or RSS feed for Free Sitetag