Jump to content

help with forcing a div to stay within it's wrapping div.


Recommended Posts

I have the following items in my CSS

 

#wrap { width: 1000px; position: relative; padding: 0 5px 0 5px; margin: 0 auto; background-color: #FFFFFF; }

#content { padding: 1em; width: 75%; position: relative; }

.status { width: 100%; padding: 5px; border-style: double; border-color: #A9A9A9; }

 

Here's my HTML

<div id="wrap">
  <div id="content" style="float: left;">
    <div class='status'>test</div>
  </div>
</div>

 

The resulting render in the browser has the status div pushing to the edge of content, but not obeying the padding of content. Why not?

The box model: http://www.w3.org/TR/CSS2/box.html

 

Since you don't define the padding (or margin) for "content", they're set as that div's content area.  Also, you set the width for "status" to be 100%.  This means that it's 100% of it's containing element - "content."  So, "status" fills up that entire area.

Can you clarify your first sentence?

"Since you don't define the padding (or margin) for "content", they're set as that div's content area."

 

As per the CSS code:

#content { padding: 1em; width: 75%; position: relative; }

I thought I was defining the padding for "content".  My intention is to have a 1em padding for Content and anything within content, should conform to that padding and not render passed that padding.

 

Thanks for the help!

Can you clarify your first sentence?

"Since you don't define the padding (or margin) for "content", they're set as that div's content area."

 

As per the CSS code:

#content { padding: 1em; width: 75%; position: relative; }

I thought I was defining the padding for "content".  My intention is to have a 1em padding for Content and anything within content, should conform to that padding and not render passed that padding.

 

Thanks for the help!

 

Ach, sorry...completely missed that.  Hmm...and the padding for "status" should be working to.  I'm betting at least part of it is that you're using relative positioning.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.