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? 🙂
ashish says
text shadow and rounded corner are awesome in looking and increase the looking of the web page.
Colin says
People really shouldn’t be afraid to mess with CSS…it’s very forgiving, and you won’t break anything. Just make sure you don’t work from your parent theme’s stylesheet! This would be a good spot to link to Lisa’s video about WP child themes but I can’t find it.
Colin says
this one…https://blog.2createawebsite.com/2011/09/05/wordpress-child-themes-why-you-need-them/
lisa says
Thanks for sharing that Colin.
Dhafian says
This is an awesome project tutorial. I really like it. Many Changes in CSS3.
?ukasz Krawczyk - Tworzenie stron WWW says
Hey, this is an interesting list of tricks for CSS3. Certainly useful for novice Web Designers.
PCTutorials says
CSS3 is a very good thing for a website because you don’t have to fill up your website with many images to implement gradients,shadows and other things.You just write some simple text that instructs the browser to implement shadows,gradients,etc.CSS3 is a wonderful thing but it is not supported by the mainstream browser Internet Explorer,which sucks.Until all people switch to Firefox and Chromium ,CSS3 will not gain as much popularity as it deserves.
Essex Pest Control and Bird Control says
Thank you, as a started to the world of building my own website I found some really useful tips here that really helped me make my site stand out.
360 Photography says
That rounded corner box one is gold – such a simple thing but it instantly makes your website seem just that little bit more professional
hellen says
thanx am getting to learn some stuff, great work lol
Postage Rates says
Thanks for the great tips. But i still not to understand to learn css3
Gayle Wagner says
I hate spending time working up some super-cool effects that only people using Opera can actually see! Thanks for sharing this with us.
aakash gupta says
Hi, I am a web designer hope these CSS3 Tricks will be useful for me. Thanks for the great post.
adumpaul says
Great useful article.Thank you for sharing.