CSS 3 Secrets for Rounded Corners and Box Shadows on Squidoo Lenses

Ranked #5,136 in Computers & Electronics, #96,832 overall

Learn How to Apply These Simple CSS 3 Tricks to Your Squidoo Lenses

Have you ever wondered how to spice up your Squidoo lenses with rounded corners, drop shadows and color gradients? This lens shows you how and introduces you to some of the most fun and useful features of the new CSS 3 standard.

If you've ever worked on a website trying to add these features yourself you'll now that up until quite recently, you had to do all this by creating your own images, chopping them up and then inserting them into your web pages. Not anymore! These new CSS 3 techniques really do save a ton of time.

Here we'll talk about how to create these techniques using CSS 3 and the special trick you'll need to use to apply them to your Squidoo lenses. Don't worry - it's really easy.

Browser support is a bit of an issue right now but don't worry - the best browsers support the new standard (that's one way of saying you might not see this lens in all of its glory if you're using Internet Explorer)! We'll cover that in a later section.

Ready for some fun?

CSS 3 Box Shadow

This is a sample text box with a box-shadow


You can make the shadow more blurry like this


or change the shadow color


Box shadow is a useful time saver. This technique used to be done using lots of little shadow images arranged around the box - a real pain to get right. This is so much simpler.

Note I added a little bit of margin on the right hand side of these boxes as some browsers cut the edge of the shadow off.

Here's some sample code to create a box shadow:

<p style="background: #FFCFAA; -moz-box-shadow: 10px 10px 5px #888; -webkit-box-shadow: 10px 10px 5px #888; box-shadow: 10px 10px 5px #888; padding: 10px; margin-right: 20px; ">Your paragraph text</p>

CSS 3 Border Radius

Do you get tired of all those square boxes on websites? Do you ever wonder how some modern websites manage those nice curved corners? The secret lies in the CSS3 border radius setting.

Here's an example of border radius 15



Here's one with a smaller radius



Set it to zero and the corners become square



Border radius lets us create rounded corners really easily, instead of creating them using multiple images. You can even define different radii for different corners or change the curvature of the corners.

Here's some example HTML code for border radius:

<p style="background: #9197FF; -webkit-border-radius: 15px; -moz-border-radius: 15px; border-radius: 15px; padding: 10px; color: black; ">Your paragraph here</p>

Browser Support

CSS 3 is a brand new standard and because of this not all web browsers support the new definitions.

Are there really that many browsers? Well, if you think of Internet Explorer, Safari, Chrome, Firefox and all the different version of these then you'll probably realise the answer is yes!

Should you worry about this? The answer is also yes, since you want everyone to be able to see your lovely design features, whichever web browser they use.

The best place to check out support for these new CSS 3 features is a website such as caniuse.com - just select CSS3 and it shows you which feature is supported by each browser.

I've added a couple of comments on browser support here, but you should always check out the official story!

CSS 3 Background Size

CSS Background is a great technique for adding colors or pictures to your backgrounds. You'll find lots of examples in the CSS Backgrounds lens right here in Squidoo. In CSS2 though it was tricky to get the size of the background image right.

Here's an orange background image.
With its original size,
this text falls outside the background



Here though we've set the width of the background image to 100%
So now it's a wide as the column
You can do the same with the height too!



Here's soome HTML to set background size:

<p style="background-image: url('http://www.infinite42.com/squidoo/css-background/css-background-orange.jpg'); background-repeat: no-repeat; -moz-background-size: 100% 100%; -o-background-size: 100% 100%; -webkit-background-size: 100% 100%; color: black; padding: 10px;">Your paragraph here</p>

Text Shadow

Here's an example of a text shadow


You can put the shadow on the other side...


...or make the shadow more blurry


...or even try a different shadow color


Text-shadow was introduced in CSS version 2 so it's not really new in CSS 3. It's a really nice feature to have though - before the only way to achieve this kind of effect was to create an image with text in a graphic tool such as PhotoShop and then use the drop shadow feature. Even better, the text with the shadow becomes crawlable content for the search engines.

So here's some example code for text-shadow:

<p style="text-shadow: 2px 2px 2px #000;">Here's an example of a text shadow</p>

A Word on Web Browsers

What are all these different web browsers anyway? The most common browsers are categorized into 4 different groups:

Internet Explorer

Often called IE, with version 6, 7 and now 8.

Firefox

Latest version is 3.6 with 4.0 due early in 2011

Safari

Safari is the web browser on your Apple Mac but there are also Windows versions available for PCs. Currently version 5.

Chrome

Chrome is Google's web browser and is built with the WebKit layout engine

Opera

A free browser with excellent standards support. It runs on many different operating systems, PCs, Macs and mobile devices

Opacity

Here's a red background with 20% opacity


Here's a red background with 40% opacity


Here's a red background with 60% opacity


Here's a red background with 80% opacity


Here's a red background with 100% opacity


The text is a little hard to read here on a Squidoo page because the opacity is applied to the paragraph as well as the background - so if the background has 20% opacity, so does the text.
Opacity isn't strictly a new feature for CSS 3 - it's actually been around for a while but wasn't a standard CSS property.

Example code for setting 60% opacity:

<p style=" background: rgb(255, 0, 0) ; opacity: 0.6; padding: 10px; color: black; ">Here's a red background with 60% opacity</p>

CSS 3 Gradients

One of the most exciting features in CSS3 is color gradients.
These let you easily fade from one color to another
without spending time creating the effect yourself using image slices.
It's also really easy to adjust



This is a nice simple example of a linear gradient between two colors, but you can do a whole lot more. You can use different colors of course and you can merge between 3 or more different colors. Or, make the fades more or less smooth.

Check out this handy CCS3 Gradients tool for playing with gradients. It even generates the code you need for your site

This HTML code will generate a similar gradient to the one shown above:

<p style="background: -webkit-gradient(linear, left top, left bottom, from(#faa51a), to(#f47a20)); background: -moz-linear-gradient(top, #faa51a, #f47a20); padding: 10px; color: black; ">Your paragraph here</p>

CSS 3 Transform

These all use the same source image.

You can rotate any element such as an image
Rotate it a bit more

Skew it

Or just scale it up or down in size

Use this code to do a similar 14 degree rotation (image 2 above):

<img style="-moz-transform: rotate(14deg); -webkit-transform: rotate(14deg);" src="http://www.infinite42.com/squidoo/css-background/css-background-orange.jpg" />

CSS3 Transitions

CSS 3 Transitions let you alter any CSS property, such as color, size or position. If you change the position of an object over time, you've got an animation!

These are a little new so browser support is a little patchy. Right now only Safari, Chrome or Opera support these features, with Firefox 4 due in early 2011.

Lots of example animations trigger on :hover but this can't be written using the inline CSS that we use here (i.e. won't work on Squidoo). So for now, bookmark this lens and watch out for the examples I'm building on infinite42.com

Combining CSS 3 Styles

Sure you can do it! You can pile on the style statements and the only trick is getting the code right. Let's have a go:

Rounded corners, shadow and transform all together!



Note the rotated text can look a little funky in some browsers.

And finally, here's the HTML again:

<p style="background: #FFCFAA; -moz-box-shadow: 10px 10px 5px #888; -webkit-box-shadow: 10px 10px 5px #888; box-shadow: 10px 10px 5px #888; -moz-border-radius: 15px; border-radius: 15px; -moz-transform: rotate(-6deg); -webkit-transform: rotate(-6deg); padding: 10px; ">Rounded corners, shadow and transform all together!</p>

How to Use These CSS 3 Techniques on Squidoo

The 'proper' way to use these CSS3 techniques is to add classes and ids to your HTML code and then put the CSS either in a separate file or in the header of your web pages. The CSS can be applied to most elements, such as paragraphs, images, links, divs and so on. Backgrounds and layout blocks are written using divs.

It's not quite so easy though on Squidoo and you do have to employ a couple of tricks to make some of these settings work. This is because Squidoo doesn't allow the use of divs or separate style sheets. it's fair enough because this helps to keep all of our lenses consistent and prevents any layout problems.

So here's the technique for Squidoo:

  • For backgrounds, boxes etc, the CSS has to be applied to the element you're styling, such as a paragraph: <p>

  • Use inline style. Like this: style="color: black";

This means it's not quite as flexible as regular HTML pages, but it works OK. Check out the examples scattered through this lens and try them out for yourself - don't be afraid to ask for help if you get stuck!

More Useful CSS 3 Reading

10 CSS3 Lightbox Alternatives
Lightboxes provides pop-up windows that display images, videos or content boxes on your web pages. Up until recently these were mainly coded using Javascript (for example jQuery) but now it's possible to create a lightbox using pure CSS3. The only downside is the limited browser support for CSS 3 right now, as we've seen already in this lens
24 ways: An Introduction to CSS 3-D Transforms
You can even do 3D transforms using CSS3. We're talking iPhone-style image flipping and more. Currently only Safari supports 3D, so it can only get better.

Want More on CSS 3?

Now you've read the lens, let us all know what you'd like to see more on. You can add your own ideas here or vote for something that's already there.

(P.S. Code examples are now included)

Show me the code

Detailed code for the examples shown8 points

More CSS 3 ideas

Show us what else you can do with CSS 33 points

More Squidoo tips

Ideas to spice up your lenses2 points

Recommend further reading

Books, websites, etc0 points

Help!

Assistance getting CSS 3 working0 points

Leave a comment here

If you have a comment on this lens or a question about CSS 3 just fill out the box below...

  • Coe Nov 21, 2011 @ 2:50 pm | delete
    Very helpful... thank you!
  • themeaparty Oct 24, 2011 @ 9:44 am | delete
    Thanks! Looking at other lens, I thought it was a module or something that I was missing (or was not a high enough level to use.) I didn't realize that writers manually put in the code.
  • LauraSchofield Oct 13, 2011 @ 10:42 am | delete
    Fantastic lens! I'm going to bookmark this for reference!
  • Srena44 Aug 1, 2011 @ 12:43 am | delete
    great lens
  • autowebsite May 25, 2011 @ 3:54 pm | delete
    Cool suggestion! Thanks!
  • Load More

by

DrRichard

Hi - I do small business website design at infinite42. I help other people build websites and also help to make them successful. You know, it's actually... more »

Feeling creative? Create a Lens!