views:

100

answers:

2
<div id="main-solutions">
   <div id="main-solutions-top-left"></div>
   <div id="main-solutions-top-right"></div>
   <div id="main-solutions-body">
       blah blah blah
   </div>
</div>

css

#main-solutions {
}

#main-solutions-top-left {
    position: absolute;
    top: 0px;
    left: 0px;
    background: url('../images/Top-Left-Gray-Corner.gif') no-repeat top left;
    width: 434px;
    height: 15px;
}

#main-solutions-top-right {
    position: absolute;
    top: 0;
    right: 0;
    background: url('../images/Top-Right-Gray-Corner.gif') no-repeat top right;
    width: 434px;
    height: 15px;
}

#main-solutions-body {
    background: url('../images/Gray-Gradient.jpg') repeat-x;
}

I'm expecting to see that main-solutions has two absolutely positioned divs at the top left and right with my rounded corner image, and then followed by the body with the gradient, but when I use HTML element browsers, the top-left and top-right div are not appearing at all, very confused, why are those divs being disregarded?

UPDATE (for others confused by answer):

At the root of my issue is I didn't understand that both absolute and relative define a new coordinate system for their contents, in addition to specifying the posision of the element itself. Found a good explanation here:

http://www.w3.org/TR/WD-positioning-970131#Positioned

from section 2.2

Like 'absolute' positioned elements, 'relative'ly positioned define a new coordinate system for child elements, with the origin located in the position where the first child element is rendered

+4  A: 

Far as i'm seeing, the corners should be appearing at the top left and right of the page, since your container div doesn't have a CSS position property. Absolute-positioned elements' positions are relative to the innermost parent that has a position other than static (the default).

Try adding position: relative to the container div's CSS. It works much like the default, but (1) if you want, you can shift the div's position by some amount (which isn't extremely useful here, but still), and (2) since the position's not static anymore, absolute-positioned stuff inside the div should position itself relative to the container, rather than to the body/page.

Also, some browsers won't even display a div that has no content -- so the background for said div might not show. You'll probably want to have something in the divs. Even a single &nbsp; will work.

cHao
isn't that going to tell the parent div that ITS position will be relative to the last element? not the contents?
walnutmon
This. When you absolutely position an element, it's coordinate system is that of the closest explicitly positioned parent element.
meagar
@walnutmon: position relative tells it to position relative to it's usual position, so if you don't set any top/left/right/bottom coordinates, it will stay in the same spot.
Robert
Yes, but it won't change its position, and elements with position are layed out relative to the nearest parent with position; if you don't define position on your parent div, then those divs end up being absolute relative to an element up the chain, like your document body.
Chris Heald
wouldn't this mean that having any div as relative in a heiarchy could mess up the positioning of anything absolutely position within it? When I say "relative" for a DIV, does anything within it, no matter how deeply nested use that as the new origin for absolute positioning? Unless something within it defines relative too.
walnutmon
I found a good documented explanation to the question I just asked, i'll add it to the question as an FYI.
walnutmon
If you have absolutely positioned elements, they should be within a parent that doesn't have `position: static` (or no `position` at all, which means the same thing). If you have something deep within the tree that you want always positioned relative to the page (or to an element further up in the tree) instead of said parent div, basically, you're doing it wrong.
cHao
+2  A: 

Have you considered using CSS border-radius to achieve this rather than messing around with images?

border-radius is supported by all browsers except IE, but even IE can be made to work with it with the use of a clever little thing called CSS3Pie.

(plus as a bonus, CSS3Pie also gives IE CSS gradient backgrounds, so you could kill two birds with one stone)

Spudley