Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Adding drop shadows

From: CSS: Page Layouts

Video: Adding drop shadows

Drop shadows are another design element that has eluded designers, in terms of having a pure CSS solution. Over the years, designers would use images, customized borders, sometimes they would even layer multiple elements on top of each other, just to achieve the look of drop shadows. Recent additions to CSS allow us to apply drop shadows directly on elements and text, using the box shadow and text shadow properties respectively. Now, before we get into this exercise and working on these values ourselves, I want to go over the syntax just for a moment. And you can see in our code block, right there we have an example of box-shadow.

Adding drop shadows

Drop shadows are another design element that has eluded designers, in terms of having a pure CSS solution. Over the years, designers would use images, customized borders, sometimes they would even layer multiple elements on top of each other, just to achieve the look of drop shadows. Recent additions to CSS allow us to apply drop shadows directly on elements and text, using the box shadow and text shadow properties respectively. Now, before we get into this exercise and working on these values ourselves, I want to go over the syntax just for a moment. And you can see in our code block, right there we have an example of box-shadow.

It's got four values separated by white space, and then a color declaration after that. Now, those four values in order. The first value is the horizontal offset; the second value is vertical offset; the third value is the blur or how sharp the shadow should be; and then the fourth value is the spread, or how big the shadow is going to be. Now, as far as the text shadow goes, the text specification says that it uses the exact same syntax, but that is not exactly true. That was a recent change to the syntax.

So as you're going to see when we do text shadow, we'll only have the three values, because most browsers don't support spread value for text shadows. Okay, we have three elements that we're going to style with drop shadows. You can see them just below our scripted text. We have the headline that says Drop A Drop Shadow On Me Please, and then we have two blocks, and the first one says The key to drop shadows is subtlety! I couldn't agree more. And the second one says, My inner shadow is showing, which should give you some indication as to how we're going to style our shadows. Okay, so I've opened up the shadows.htm file.

You can find this in 08_04 directory. Just to give you an idea of the elements that we're going to be styling, I am going to scroll down into the code. You can see that you have a section of shadows. The first one has the h2. Then we have the div tag of class of outer, and we have another div tag with a class of inner, and that is who we are going to be styling. Okay. So I am going to go up a little bit and you can see we have some empty selectors here and I am just going to start on the shadows h2. We're going to do some text shadows. So I am going to do the text-shadow property, and for the text-shadow I am going to do a 2-pixel offset for horizontal.

I am going to do a 2-pixel offset for vertical. I am going to end up with a 10-pixel blur. And then I am going to give it a color of, let's say #666, which is sort of a dark-gray color. All right! So I am going to save that, go into my browser, refresh the page, and there is our drop shadow. You can see when text is involved, your blur really matters, and it can make the object look like it has sort of a glow to it. I mean there are lots of different things that you can do to it. If I were to come back and make that even darker, say I go black, save that, and test it, you can see, because of the blur, we're not really seeing black.

Now, if I go back in and change this blur value, let's say I change that to say 5 pixels and I save that and I preview it again, now the shadow is getting a little bit clearer. But because of the way that we've done the text--the text is a light gray itself--it's really making the text look really blurry. And you have to be very careful when using drop shadows on text because you don't want to negatively impact the readability. Now, one technique that a lot of people are using with drop shadows on text is to make the text look either a little beveled or a little embossed, depending upon whether it's light text on a black background or dark text on a light background.

So if I go back into my text-shadow and I change a few things, let's say I change the offset to only 1 pixel for both horizontal and vertical, and then I change the blur to 0, no blur whatsoever, and then change the color value from the current black to that dark gray again, save that, go back out and preview it, and you can see what's happening here now. We've got a slight offset to the shadow. We've got that really sort of clearly defined shadow, and it's giving us appearance of the text being a little beveled.

And you can work with those values to further refine them. And another thing that you can do is you can add multiple text shadows. You can have comma-separated lists of them, so you could offset a lighter value to the top, and you could offset a darker value on the bottom and really sort of complete that illusion. Okay. So those are text shadows. I want to go down and talk about box shadows now. So I am going to go to my outer and my inner ones, and I am just going to start off with the box-shadow property. Now, I want to go back up to text- shadows for just a moment because I forgot something that's really, really important.

Text-shadow, you'll notice I didn't use any vendor prefixes there. It's fairly well supported among modern browsers. Unfortunately, currently Internet Explorer does not support text-shadow. All right! So for box-shadow, I am going to do box- shadow and I am going to do 5 pixels for the horizontal offset, 5 pixels for the vertical offset. If you're wondering, can I use negative values to move it up and over? You absolutely can. You're not restricted to positive values here. Then I am going to do 5 pixels for the blur and then again 5 pixels for the spread.

So I am making that very even. I am going to do #333 for the color. Now, box-shadow is something that is also well supported by modern browsers, including Internet Explorer 9; however, we do have to use vendor prefixes. So I am going to copy this, and then I am going to paste it a few times, and I am going to add the -moz for box- shadow and the -webkit-box-shadow. That should cover my bases for right now. So I am going to save that, go up and preview it, and you can see our drop shadow right down here.

It's a pretty strong drop shadow. It's 5 pixels over, 5 pixels down. Fairly dark. You can see the blur and the spread. Now, if you're wondering exactly what the difference is between blur and spread, I am going to flip over to the CSS3 background module, the Backgrounds Level 3 module. They have a great illustration here in this specification. Essentially, if you look at the border box shape, the spread is applied outside of that. So it goes outside of that based on the number of pixels you are asking it to go. And then the blur radius is applied sort of midway between the spread.

So you can see midway between the spread and the edge of the shadow, that's where the blur is applied. Same thing for the inner shadows. And we're going to apply an inner shadow in just a moment. All right! So I am going to go back on to my page, I am going to move back into my code, and I am going to start modifying some things here. Now, the vendor prefixes that we have here, the Mozilla and the WebKit one, they are really for older versions of Firefox and Chrome and Safari. Their most recent versions support it without the prefix on it. So I am going to experiment with these values a little bit. just so you can see kind of what they're doing, but I am not going to modify these vendor prefixes here because there's no reason for me to do it three times just because I am testing it. All right! I am going to take the blur and I am going to move the blur down to 0, and then I am going to take the spread and I am going to crank the spread up to 10 pixels.

So I am going to save that, go back in and refresh, and you can see big difference between spread and blur. We offset the shadow, but because of the distance in the spread, it's actually popping out a little bit on the top there as well. Now you can use negative values, as I mentioned before. So if I come in, for example, I could say -5 pixels for the spread. If I save that and test it, you can see it's hiding it altogether. Now, I could come in for the blur and say, okay, give me 10 pixels on the blur, and if I save that and test that, you can see it's kind of restricting it; just the very edges of that blur are sticking out.

So the more I increase the value of the spread, I mean even if I take the spread from a negative value to 0 and save it, you can see the effect it's having on it, and it's now starting to once again poke out the other side up there as well. So if you want to restrict it to one side, you might want to think about using a bigger blur and maybe a negative spread. Okay. Now, we also have the ability to do inner shadows. So what I am going to do is I'm going to copy these particular styles and then I'm going to paste them in the inner shadow, because creating an inner shadow is actually extremely easy.

All you need to do is add the inset keyword. So right in front of each of these properties, I am just going to do inset. So it's a new keyword, and it just shows up right there in front of them. And then finally I'm going to modify these values a little bit, because inset shadows, if I left it the way it is right now, if I save this and previewed it, you can see that inset shadow is really, really harsh. That's an interesting view. It applies the shadow obviously on the inside, and it sort of creates almost a three-dimensional effect on your elements.

But again, I really believe in subtlety when it comes to things, and if you're trying to style buttons, this is a property that you definitely want to experiment with. So I am going to come in and I am going to set all of my offsets to 0. So I am just going to go ahead and do 0 for all of my offsets, and I'm going to go ahead and make all the syntax match, just because. And then what I am going to do for the blur is I am going to do a 10-pixel blur. So I am going to do a 10-pixel blur, and if I was a smart guy, I would just do it once and then copy and paste it.

And then for my spread, I'm going to do -2 pixels for the spread, and then I will just copy those values and then paste them for each one of these. And that's a little bit smarter. Okay, so again, no offsets whatsoever, and then for the blur, we've got two of them. We don't need three. For the blur, I am going to do a 10-pixel blur and for the spread, I am doing -2 pixels, which again is going to lessen the severity, if you will, of the drop shadow. So I am going to save this and then when I preview it, you can see the shadow is applied equally all the way around because we don't have an offset.

Because the spread is negative, the shadow doesn't go too far into the element, and that blur is creating a real soft edge for this. So it's a really easy way to create buttons and things like that by using the sort of inner shadows, especially if you're also using gradients for the background fill. Okay. So that's just a brief introduction into drop shadows. If you want to learn a little bit more about them, I have got some links here to the text level 3 specification, which has text-shadow and the CSS backgrounds and borders module level 3, which has box-shadow in it. Honestly, everybody has got their own really distinct opinion about drop shadows.

They are one of the more polarizing aspects of design. Period. Not just web design. Some designers love them, while others, not exactly fond of them, but as with all stylistic choices that you are making, whether you use them or not is really going to come down to personal choice and your own design aesthetics.

Show transcript

This video is part of

Image for CSS: Page Layouts
CSS: Page Layouts

71 video lessons · 41412 viewers

James Williamson
Author

 
Expand all | Collapse all
  1. 4m 20s
    1. Welcome
      54s
    2. How to use the exercise files
      3m 26s
  2. 1h 39m
    1. Box model review
      8m 47s
    2. Calculating element dimensions
      11m 11s
    3. Understanding margin collapse
      7m 59s
    4. Calculating em values
      7m 41s
    5. Calculating percentage values
      7m 51s
    6. Normal document flow
      13m 3s
    7. Controlling element display
      8m 53s
    8. Using CSS Resets
      7m 11s
    9. Fixed, fluid, and responsive layouts
      9m 9s
    10. CSS debugging tools
      6m 46s
    11. Using the Firebug Inspector and the WebKit Web Inspector
      11m 5s
  3. 53m 15s
    1. Page design workflow
      3m 6s
    2. Page design tools
      4m 56s
    3. Determining page structure
      7m 18s
    4. Creating image assets
      8m 58s
    5. Creating initial page structure
      7m 3s
    6. Adding meaning with classes and IDs
      5m 23s
    7. Structuring content with HTML5
      6m 6s
    8. Building internal structure
      10m 25s
  4. 1h 36m
    1. Floating elements
      7m 50s
    2. Clearing floats
      7m 28s
    3. Containing floats
      7m 50s
    4. Clearfix technique
      10m 38s
    5. Floating inline elements
      14m 34s
    6. Two-column floated layouts
      8m 17s
    7. Three-column floated layouts
      11m 30s
    8. Column height considerations
      7m 3s
    9. Creating equal-height columns
      10m 42s
    10. Floats: Lab
      5m 25s
    11. Floats: Solution
      5m 21s
  5. 51m 42s
    1. Relative positioning
      7m 59s
    2. Absolute positioning
      8m 59s
    3. Fixed positioning
      4m 23s
    4. Controlling stacking order
      8m 31s
    5. Clipping content
      8m 21s
    6. Controlling content overflow
      5m 38s
    7. Positioning elements: Lab
      3m 59s
    8. Positioning elements: Solution
      3m 52s
  6. 48m 46s
    1. Design considerations for fixed layouts
      3m 28s
    2. Establishing the layout grid
      7m 57s
    3. Defining column spacing
      9m 30s
    4. Applying the grid through CSS
      8m 56s
    5. Creating grid-based assets
      8m 26s
    6. Grid design resources
      6m 22s
    7. Building fixed layouts: Lab
      4m 7s
  7. 44m 35s
    1. Designing for flexible layouts
      2m 30s
    2. Calculating percentage values
      8m 45s
    3. Setting flexible width values
      6m 6s
    4. Making images flexible
      8m 10s
    5. Setting minimum and maximum widths
      7m 24s
    6. Building flexible layouts: Lab
      4m 53s
    7. Building flexible layouts: Solution
      6m 47s
  8. 49m 36s
    1. Responsive layout overview
      3m 49s
    2. Using media queries
      7m 16s
    3. Organizing styles
      8m 39s
    4. Making content responsive
      8m 33s
    5. Mobile design considerations
      7m 32s
    6. Building responsive layouts: Lab
      4m 23s
    7. Building responsive layouts: Solution
      9m 24s
  9. 1h 22m
    1. Creating multi-column text
      6m 36s
    2. Using borders to enhance design
      13m 59s
    3. Rounding corners
      6m 56s
    4. Adding drop shadows
      10m 35s
    5. Working with opacity
      6m 8s
    6. Utilizing the background property
      15m 5s
    7. Working with CSS sprites
      7m 58s
    8. Enhancing page design: Lab
      6m 22s
    9. Enhancing page design: Solution
      8m 38s
  10. 6m 25s
    1. Additional resources
      6m 25s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed CSS: Page Layouts.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.