views:

160

answers:

3

Here's a screenshot:

header

The red bar on the left is the background I set for the #personal div and I would like it to align to the top of the container, vertically.

The problem is that I have a background for the #container-top div on top of the #container div with absolute positioning. Is there any way to move the #personal div up so there would be no space left?

HTML

<div id="container">
  <div id="container-top"></div>
    <div id="personal">
      <h1>Jonathan Doe</h1>
      <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliqua erat volutpat.</p>
    </div> <!-- end #personal -->
</div> <!-- end #container -->

CSS

#container {
  background: url(images/bg-mid.png) repeat-y top center;
  width: 835px;
  margin: 40px auto;
  position: relative;
}

#container-top {
  background: url(images/bg-top.png) no-repeat top center;
  position: absolute;
  height: 12px;
  width: 835px;
  top: -12px;
} 

#container-bottom {
  background: url(images/bg-bottom.png) no-repeat top center;
  position: absolute;
  height: 27px;
  width: 835px;
  bottom: -27px;
}

#personal {
  background: url(images/personal-info.png) no-repeat 0px left;
}
+1  A: 

Change the following CSS:

    #personal {
  background: url(images/personal-info.png) no-repeat 0px left;
position: relative;
top: 0px;
left: 0px;
}

You need to position this element relative to it's parent; container, so that it fits where you want. The top and left properties are how far away from the top left corner of the parent div you want the particular element.

Or this:

#personal {
      background: url(images/personal-info.png) no-repeat 0px left;
    margin-top:-10px; /*px value that works*/
    }

This will take its current position within it's parent div and render it 10 pixels higher than it is currently positioned.

Kyle Sevenoaks
This doesn't change anything at all, does it?
ANeves
As far as I see, it should shove it up where he wants it, or have I gotten something wrong?
Kyle Sevenoaks
The container-top background disappears.
Norbert
Try changing it to `position:absolute;`
Kyle Sevenoaks
I have other content below the personal div.
Norbert
Or perhaps a `margin-top:-10px;/*px value that works*/` might be the way to go?
Kyle Sevenoaks
`#container-top` is not `#personal`'s parent, btw.
ANeves
No, it's not. I am reading his code all skew-iff. rethink and rephrase. I think a negative margin might work.
Kyle Sevenoaks
+1  A: 

[Edit: revamped.]

HTML:

<div id="container">
  <div id="container-inner">
    <div id="personal">
      <h1>Jonathan Doe</h1>
      <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliqua erat volutpat.</p>
    </div> <!-- end #personal -->
  </div> <!-- end #container-bg -->
</div> <!-- end #container -->

CSS:

#container {
  background: url(images/bg-mid.png) repeat-y top center;
  width: 835px;
  /*margin: 40px auto;*/
  margin: 28px auto 40px auto;
  position: relative;
}

#container-inner {
  background: url(images/bg-top.png) no-repeat top center;
}

#personal {
  background: url(images/personal-info.png) no-repeat 0px left;
  padding-top: 12px;
}

Is this according to what you wish to do?

ANeves
That would be a better way to do it.
Kyle Sevenoaks
The backgrounds are transparent, so setting them on top of each other would create a double shadow.
Norbert
But you asked to move the 3rd background up. How will it not create a double-shadow as well, the way you ask it? Please clarify.
ANeves
I totally misunderstood the question. Let me think and rephrase.
ANeves
+1  A: 

Unless if I'm missing something, I see what you posted producing the results you want.

I'm wondering if you've applied a reset CSS to your styles? If not you could look at the yahoo user interface css reset or Eric Meyer's reset CSS.

The browser might have some default padding and margin spacing.

You include the reset CSS before your other styles. Perhaps you already know this, but it's worth asking.

digitaldreamer
I have a reset file. I don't want the gap above the red background.
Norbert