ars aranea. the web, the way we make it. | |||
52 Car crusher drop shadowsPosted: Feb 27, 2006, under Graphical design, DHTML. Updated: Aug 21, 2006. Add a comment!1. IntroductionYou all know how to create rounded corners with nothing but 4 Let’s start from the rounded corners technique and see if we can build an all-around shadow which can adapt to whatever size the inside container takes.
I’m not going to insist on classical drop shadows, which you probably read all about on A List Apart. That’s because those techniques and this one don’t have that much in common apart from the idea of using positioned backgrounds. We’re trying to surround a box (id 2. DemoFor the impatient ones, here’s the demo and the stylesheet. Yes, yes, I didn’t make up for Internet Explorer’s lack of PNG transparency. It still works, even if it looks ugly. I’m not familiar with any technique that allows for PNG transparent backgrounds for boxes of variable size to work on Explorer 6-. You should also read the “Complications” section below to understand why I did some things the way I did. 3. ExplanationFirst, you have to create eight slices of shadow, which will be used to form the entire big one. You need four rectangles for the corners, two 1px wide slices for the top and bottom shadows, plus two 1px high slices for the left and right shadows. You can produce a full shadow in many graphical editor applications, then you can slice what you need from there. Check that they align properly. We’re going to arrange the eight shadows in eight places around the main box, which we’ll call using cardinal directions: NW, N, NE, E, SE, S, SW and W, for easier orientation. First, we replicate the rounded corners technique exactly. We position each corner shadow in its own box, non-repeatable, and we overlap the four The innermost corner box (let’s say SW) will use a left and right padding to compress all the inner boxes. We do this so that the top and bottom shadows in the immediately following boxes won’t overlap the corners. Then we have to place the North and South backgrounds at the top and bottom of the N and S boxes, respectively, with For the side shadows we pull a very similar trick, but now we’ll switch to using left and right margins. Negative margins, even. The reason is that up until now we’ve crushed the boxes, but we went too far. For the last two shadows (the sides) we need to expand back, sideways, to align ourselves with the corners again. So, apply negative left and right margins to the E or W box, as well as the respective shadows as backgrounds, with Finally, we’re down to the last box, which has the actual content. But before we can fill it, we need to crush it sideways once more, using (positive) margins, because otherwise it would be left expanded. 4. ComplicationsThere are some things that stop this technique from being perfect, for the time being. It all goes well until the inner-most box, where very weird things start happening. 4.1. Content margins compose with the bordersIf we have any elements with non-null margins, inside the main box ie. in the actual semantic content, then their margins go outside the main box and compose with the top and bottom shadow boxes. They cause them to grow, thus breaking the continuous shadow effect. However, if we only enter inline elements in the main box, or we take care not to have margins for the top-most and bottom-most element, all works well. Here’s an example using an Step two on the road to Weird-Town: the moment we apply a border or a padding on the inner-most box, browsers such as Mozilla [Firefox] or Opera suddenly fix the margin composition problem. I have no idea why and it seems silly to me, but then again I’m not a CSS guru. So, if you have a border or padding, things happen as you’d expect them to: even if inner elements have margins, they cause the box to grow, they don’t cause spacing from the other outer boxes. Here’s how it looks now: Example #2. So, to work around this problem, either make sure than the contents doesn’t have margins, or apply borders and/or padding to the content area. There are various ways to tackle the margin issue:
4.2. Explorer: box background runs over the containing box’s paddingLooking good so far, right? Wrong: here comes Internet Explorer. It also fixes the problem, but introduces a new one: now the W/E boxes (used for side shadows, magenta in the example) suddenly decide to ignore the In other words, in IE, the content of the box respects the This second problem can be “solved” by using the inner-most box (
I’m really sorry for having to resort to such tricks and even tables. But even if it bothers you, please keep in mind that we’re using a whole bunch of non-semantic
| Important
Categories
Authoring
(1)Books (2)Cross platforms (2)DHTML (12)Graphical design (3)IT today (12)Morals&Politics (10)ODP (1)Random stuff (3)Romania (16)Security (7)SEO (2)Software (8)SQL (1)Standards (7)Technology (3)WordPress (4)[În română] (4)[This website] (2)Time-jump Syndication Need hosting?I've been a happy user of LunarPages since 2005. |
||
Copyright ©2005–2008 Zuavra | |||