If you’re one of those people who shuts down or goes cross-eyed when you read anything about CSS, stay with me.
You guys know how I roll. I will make this as painless and easy for you to implement as possible — at least that’s my goal anyway. The code is provided below so all you need to do is copy and paste.
I’ve been taking some time to learn more about CSS3, which allows you to do more styling on your site with minimal code and images.
Cleaner code and fewer images ultimately means faster loading pages and it’s better for SEO (less code for the engines to wade through.)
I’ve been slowly implementing a few CSS3 tricks here and there so I developed this mini tutorial on how to take advantage of the border, box and shadow properties. Because not all browsers support CSS3, I haven’t gone too crazy with implementation just yet.
The CSS Border/Box Properties
In this post I’m going to focus on adding rounded corners, image borders and shadows.ย Before CSS3, creating rounded corners and shadows was a royal pain.ย You had to use an image and position them using coordinates.ย But with CSS3, it’s a breeze!
1) Creating Rounded Corners
The border-radius attribute creates rounded corners around an element. This code works in IE, Firefox, Chrome, Opera and Safari.
The first thing you need to do is paste the following CSS code into your style.css file. Feel free to adjust the color, width, padding, etc.
div.rounded
{
padding:10px 35px;
background:#eed9a8;
border:2px solid #000000;
border-radius:20px;
-moz-border-radius:20px; /* For Firefox 3.6 and earlier */
width:250px;
}
Now in your post you simply use…
<div class=”rounded”>This text will be surrounded by an object with rounded corners</div>
And this is the result…
2) Creating a Border With an Image
CSS3 allows you to use an image as a border. This does not work in IE — shocking, I know. ๐
So let’s say you want to turn the following image into a border…
This is a simple image I created in seconds using Photoshop’s Custom Shape Tool. To turn this into a tiled border, add the following code to your style.css file…
div.border
{
border-width:15px;
width:225px;
padding:15px 20px;
}
#tiled
{
-moz-border-image:url(redBox.gif) 25 25 round; /* Firefox */
-webkit-border-image:url(redBox.gif) 25 25 round; /* Safari and Chrome */
-o-border-image:url(redBox.gif) 25 25 round; /* Opera */
border-image:url(redBox.gif) 25 25 round;
}
Don’t forget to upload your own image and change the name and path of the image named redBox.gif or this won’t work.
Now, in your page, add the following code…
<div class=”border” id=”tiled”>This image is tiled/repeated around the text</div>
And this is the result…
You can also stretch the image border with the following CSS code…
div.border
{
border-width:15px;
width:225px;
padding:15px 20px;
}
#stretched
{
-moz-border-image:url(redBox.gif) 25 25 stretch; /* Firefox */
-webkit-border-image:url(redBox.gif) 25 25 stretch; /* Safari and Chrome */
-o-border-image:url(redBox.gif) 25 25 stretch; /* Opera */
border-image:url(redBox.gif) 25 25 stretch;
}
Now paste the following code into your actual page…
<div class=”border” id=”stretched”>This image has been stretched so it takes on a slightly different shape</div>
And the result is this…
3) Creating a Box Shadow Effect
This is a great trick to use if you want to create a shadow box effect around your text, image, etc. You can also use this to add a shadow behind your site’s container. This works in all later versions of IE, Firefox, Safari, Chrome and Opera.
Here’s the CSS code…
div.shadow
{
width:400px;
height:25px;
background-color:#ddd;
-moz-box-shadow: 8px 8px 5px #999; /* Firefox 3.6 and earlier */
-webkit-box-shadow: 8px 8px 5px #999; /* Safari */
box-shadow: 8px 8px 5px #999;
}
Now paste the following into your page…
<div class=”shadow” id=”stretched”>This box will have a shadow behind it</div>
And it will look like this…
You’ve just created an image-free shadow box! Again, feel free to adjust colors, shadow sizes, etc. by editing the CSS code.
4) Creating a Text Shadow
I’m not a huge fan of this CSS3 trick because I think text drop-down shadows can make your site look it’s straight out of 1996.
The key is to make it very subtle by using a shadow color that’s very close to the text color and minimize the shadow spacing.
Text shadows do not work in IE. Again, very shocking. *sarcasm* ๐
Paste the following code into your style.css file…
h1.shadow
{
text-shadow: 3px 3px 3px #cc7777;
color: #d22929;
}
To call up the shadow, simply paste…
<h1 class=”shadow”>This text will have a shadow</h1>
And it will give you this…
This text will have a shadow
Notice the shadow is a lighter pink color. Of course, you can change the color of the text and shadow by updating the CSS.
Now you can successfully pimp out your site with CSS3! Don’t you feel current and hip? ๐
Richindesign says
I wish theese styles were more supported and easier to accomplish, nice exmaple lisa
BestCalgaryDrivingSchool says
Great article Lisa! I have been searching for some easy to use CSS code portions and cant thank you enough for these.
Thanks!
Christine says
Hi, Lisa,
Maybe you can help me fix my mess. I somehow “lost” my main url for this site and instead have a post with a permalink rather than domainname.com/
I don’t know how to get the main url back again. It’s a paid for WP Adsense site that auto-populates Adsense ads in strategic places on the pages. The ads were not showing up on the home page, and my “stroke of genius” told me that I was supposed to make my home page a sticky post instead of a page. The ads show up everywhere else but on the home page.
Any ideas?
Thanks,
Christine
Christine says
Oh, Lisa, I forgot to mention above that I see the ads on Safari but not on Firefox or Chrome.
Thanks again,
Christine
Luke says
Thanks Lisa, I have been building websites in old skool HTML for ages using tables and cells and images for rounded borders etc… My graphic / web designer mate only uses CSS to build his sites now and has been on at me for ages to learn it. Your simple examples of how easy and cool it can be has just inspired me to get my act together and learn this now…. nice1
Mohsin ali waheed says
Awesome Css3 tricks specially i like rounded corner trick. I will definitely use it on my blog.
Mary Jones says
hey thanks for those simple tricks, i’m gonna use them on my new blog.
I like the one with the custom border using an image, that looks really neat.
Richindesign says
Box shadow is a nice effect, trying to acchieve the effect in photoshop can be a pain, thanks lisa
Jeff-H says
Great post Lisa! just wanted to say thanks for all the great info. Also just wanted to share some free tools to help with generating the code.
http://www.css3.me/
http://css3.mikeplate.com/
http://www.colorzilla.com/gradient-editor/
http://validator.w3.org/
Luke - Web Designer Worthing says
Brilliant, i have been using photoshop to get these effects as it was easy, with this tutorial – which is easy to implement – i can really make my websites faster.. thanks.. Luke
wholesale electronics says
I am familiar with the most of tricks lisa wrought here but the second trick โCreating a Border With an Imageโ is very cool.
Genie says
Oh Lisa, you really is such a dear. I have a very great confusion on this that I mostly go tend to my brother for it to get it done. I never had a knack reading such complicated tricks but here you have shared and even made available the interfaces which we will encounter and have given the solution on what to do.
I am very grateful for this tip. And also thanks to my brother, he is such a lousy tutor ๐ but I still thank him.
Happy Day Miss Lisa ๐
genie
Slappit says
The only ones i would personally use are the rounded borders, text and div background shadow.
Good blogging though, thanks
dlabacs says
Hi Ms.Lisa, ..I ever wonder how you get on top google search. I really love your videos on youtube , I really love how you present a tutorial and I think I’m in love with you.(^_^) ,
It’s another great post/tutorial from a techiepreneur Lisa,..
Brayden Seekamp says
This is the most helpful post I have ever read, know that cs4 and cs5 is the latest but they still don’t got the kick of cs3.
Thanks your a big help hit me up when you got another tricks cause some cs tuts cant really help
furniture software says
This is interesting and well explained. Maybe Iโll try some of your CSS โtricksโ on my blog and see how it will look. ๐
sokun says
I like this post mainly because i hate css codes. This could prove helpful when i need to add more code.
Sahil says
Great start Lisa. Its good to know that you’re trying to learn CSS3 all on your own. All the best!!!
Hope you will be a CSS expert one day. ๐
Shelli says
So, are we suppose to put the codes in the style.css or custom.css? I’m being prompted to use the latter. Will it work either way? I’ve tried both (cutting and pasting the code to my site) and haven’t been successful. I’m sure I’m missing something simple. But what?
lisa says
The part highlighted in gray goes in your style.CSS file. The div id= part in italics either goes in your custom functions file or text widget if you are adding to your sidebar for example.
lisa says
Also for Thesis the style.CSS is equivalent to custom.css
Dekorasyon says
I love your post, and CSS3 is just epic! You should also check transition effects of CSS3.
Gogi says
Thanks Lisa For Sharing this Great CSS3 tutorial.CSS3 really got new cool features .
Shelli says
That looks really interesting. Would definitely add visual interest to my posts. As well as break up the content so readers can easily find the good stuff. Nice to have another trick in my arsenal besides bold and italicized words (LOL)!
ravi says
cool tips, i am going to try this!
John says
I use the text shadow effect all the time, but i usually use a white shadow on a darker background to give a letterpress type effect
Kerala Tour Packages says
Thanks lisa for the tip! I was trying for quite long to get a stylish background for some text in my website. Keep up the good works and continue to post more techie ideas like these ๐
Nathal says
Excellent list of tips. Itโs worth mentioning 2 additional things in order to simplify CSS and improve browser rendering speed:
1. Avoid using the very common * star attribute for margin and padding resetting (*{padding:0}) and use specific tags instead (h1, h2{padding:0})
2. Try to classify elements in a way that you donโt use more than 2 selectors in a definition (for example, instead of #sidebar ul li a{color:red}), add an id to that ul and type (#ulId a{color:red})
Thanks
lisa says
Great tips, Nathan! Thanks. ๐
Oblikovanje strani says
HTML5 is fantastic for sure. It wont push flash back to oblivion as many said, but it does the job much better than its precursor. Anyway, what i wanted to say in first, i very much appreciate multiple backgrounds option that came with css3. Not that round corners using style sheet are not absolutely great.
Thanks for sharing this with us.
Suresh Khanal says
That’s awesome Lisa, especially the stretchable image border. Knowing little bit of codding always adds power to your creativity. I’m adding a few codes to my CSS file as well.
Thank you for the codes with examples.
London Pest Control says
I have created my website through google sites and I am finding that some things are limited in terms of what you can do on individual pages such as edit each pages header. I have many images on my site, if you look at it on a mobile also it is all jumbo mumbo. I am not to great on all this and have self taught myself all that I do know, which after much hard work has got me in a decent position for certain keyword phrases on google. But…As far as images go, I just put them onto the site via uploading from my computer, do not really know about the code side of things, guess it may be harming my seo?
KevinCrew says
Very Nice Artice. But actually I have come to your blog through google search while search for “commentluv”. I have watched that most of the blogs are using commentluv these days and thats really awesome. Anyway, I have go through your whole article and thats really nice. Thanks for such an interesting article sharing.
what is css says
I didn’t know about using an image as a border. Thanks for sharing. (It seems that css is doing more and more of what had to be done in photoshop with images.)
NICO VENGEANCE says
nice tips… I’m really interest and make me sure for css upgrade in my site…
Stephen says
Hi Lisa,
Great tips!! I love to add those little borders just to spice up the site a little. I think it goes a long way with really very little effort.
It is a bummer that IE doesn’t acknowledge the code, but that’s also a very nice subtle reminder that you must check each browser when making changes. I know IE is the easy target (as it should be), but all the browsers have little tweaks about them that just boggles the mind.
John Garrett says
Good ones, Lisa!
I’m another one of those “It woulda worked so well if not for that blasted Scooby Doo, er, Internet Explorer!” type of people.
Man this could all be so easy. For me, I really don’t cater to IE at all, but then you get that client who only uses IE and you have to scrap the cool code and use an image or something. Grrrrr…!
Thanks for the tips!
lisa says
I hear ya John. I’ve stopped catering to IE folks too for the most part. Can’t wait until that dang browser is obsolete! ๐
Computer Repair says
CSS is always fun to play around with. But it is kind of sad that IE is just behind with the times and refuse to enable these kind of features…
Well it is laziness or just don’t want to go that way. Beats me.
kunal says
Hey lisa, good job done by you though not from a computer science background. This small small things matter a lot in the blogs and websites. hey can u tell how come you developed interest in this field?;)
namco pools says
Cleaner code great help in better ranking for your site
William says
I love CSS3, in theory; the problem is that so many browsers aren’t really ready to take advantage of it. I hate spending time working up some super-cool effects that only people using Opera can actually see!
lisa says
Agree, but if you check W3 Schools, most browsers support these tricks (except IE). And the good news is, more and more people are leaving IE for Chrome, Firefox, Safari and Opera. In a year or two we won’t have to worry about browser support as much as we have.
askblasters says
thanks for the tricks gonna try them out right away
Paula Mooney says
Thanks for the simple code tricks.
I just may use them someday.
I especially like that rounded corners around text trick. Looks good. I feel a new niche site coming on… ๐
Vince says
I have bookmarked this page to come back. I’ve been wanting to make rounded corners and thought I would need an image for that.
I like the shadow effect on text too.
Thanks Lisa for these great tips on CSS 3. Will definitely try them out.
Yajaira says
Lisa, I’m a 24/7 webdeveloper, and really interested in new CSS3 scripts. thank you for making this post
virendra rajput says
Hey Lisa please review my blog I have really worked hard on it and would like that you review it for just a sec!
http://www.teckzone.in
Thanks
virendra rajput says
Hey Lisa please review my blog I have really worked hard on it and would like that you review it for just a sec!
Thanks!
Shredder says
I just got my site fixed up with your easy starter templates. I’m not sure if I’m ready to go CSS3 crazy just yet. I’ll keep this in mind though when I want to give something extra emphasis.
Sunil from The Extra Money Blog says
love the simplicity as usual Lisa. I love the rounded corners and will definitely try it out.
Samiullah Khan says
It’s good that lisa turned over to teaching css3. Hope we will see much more advanced tricks of css3. I am familiar with the most of tricks lisa wrought here but the second trick “Creating a Border With an Image” is very cool.
Flo | Create Your Own Website says
I love the wonderful displays we can achieve with CSS3 and the box shadow is my favorite! It’s unfortunate that our BFF browser IE ๐ will not let us show off these designs on our sites.
Good stuff!
lisa says
IE needs to be shot and killed. lol Fortunately fewer people are using it these days.
Flo | Create Your Own Website says
lol. Just let me know what its happening, I know a Sharp Shooter!
Jeremy Johnson says
“IE needs to be shot and killed. lol Fortunately fewer people are using it these days.” Preach it, I second that.
PTB Support says
Third from me…
I always design sites for firefox, tweak them for safari, chrome and opera – then rewrite them for IE.
Until MS either drop IE, or stop making their own standards I think this will always be the case.
Although globally firefox’s Market share is increasing, over here in the UK 80% of the visitors to my site still use IE.
:/
Brankica says
Most of the CSS stuff I learned was from your videos and codes you posted on the website. And sometimes, I just study what you do with Firebug (which I know about because of…yes, you guessed it – YOU again).
I actually use the shadow stuff, I learned about it a few months ago, and now I am using it for some of the H code.
I love the effect you can achieve with it.
I love the first part of the code, that is something I can use a lot, the borders, different colors for different purposes, etc.
Adeline says
I’ve been following your blog for a quite sometime now, and I must say you’ve made my life starting out to blog less painful. Can’t wait to try these. Many thanks!
GNS says
I’ll have to give these a shot. Boy what a techie Lisa. I guess you come from a computer science background?
Greg
lisa says
Ha ha! No, not at all. ๐ Computer science requires you to take math and I’m horrible at it. I’m self taught on the web stuff.