0

I'm using this code...

<div id="app">
    <div id="app-actionbar">
        topbar
    </div>
    <div id="app-userinfo">
        sidebar
    </div>
    <div id="app-content">
        content
    </div>
</div>

/** Styling **/

#app {
    border:1px solid #666;
}

#app-actionbar {
    color: #333;
    width: 900px;
    float: left;
    height: 45px;
    background: #D9D9DC;
    margin-top:10px;
}

#app-content { 
    float: left;
    color: #333;
    background: #FFFFFF;
    height: 350px;
    width: 725px;
    display: inline;
}

#app-userinfo { 
    color: #333;
    background:#F2F2F2;
    height: 350px;
    width: 175px;
    float: left;
}

However, it's not working like I want it to.

I want to add a border around it, but its not working (and its moving the content down).

enter image description here

5
  • Which part do you want to add the border to? Commented Jun 9, 2011 at 1:55
  • You will have to be a bit more clear or supply an image of how you want it to actually look without the SO community guessing what you actually want to achieve. Commented Jun 9, 2011 at 2:00
  • I can tell what he wants... It's not a mystery. jsfiddle.net/P9AQp Commented Jun 9, 2011 at 2:02
  • @Jared, arrr, that layout pretty much looks like his screen shot (of what the problem is) Commented Jun 9, 2011 at 2:04
  • @Dan - Yes, I know; it's his exact posted markup/css. It wasn't difficult for me to see the problem when I looked at it. ;) Commented Jun 9, 2011 at 2:05

5 Answers 5

3

You need to clear the floated elements in your #app . Try adding overflow:hidden; or overflow:auto; to #app. That will get the border to wrap you entire DIV.

Here's a live jsfiddle link of your above snippets with the overflow:hidden assigned: http://jsfiddle.net/AhZAU/

The spacing at the top, "(and its moving the content down)", is being created by the margin-top:10px on the #app-actionbar. Remove the margin and the space will no longer be present: http://jsfiddle.net/AhZAU/1/

Sign up to request clarification or add additional context in comments.

7 Comments

There are two parts to this question: "I want to add a border around it, but its not working (and its moving the content down)."
The border isn't working because the floated elements are not cleared. And it's being pushed down because he has a margin-top:10px assigned to the #app-actionbar DIV.
@thirtydot, I interpreted the question as in "I want the border to go all the way around but it's not working and instead is creating a margin space at the top". Which I guess is clear, once I've read over it a few times =P Cheers.
I'm not sure either, but his text "content" definitely looks in the wrong place to me, so that's why I think it's that. Let's wait for some feedback from the OP.
@Dan - I'm pretty sure @thirtydot is right. I had seen it down there but it' didn't register with me, I just thought it was odd. On second thought, I think @thirtydot's right.
|
2

The QuirksMode Way©:

#app {
    border:1px solid #666;
    overflow: auto;
    width: 100%;
}

http://jsfiddle.net/CePt6/

From the article:

If you want to add, say, a border around all floats (ie. a border around the container)...

NOTE

As far as the gap at the top, you can eliminate that by removing margin-top: 10px; from #app-actionbar.

#app-actionbar {
    color: #333;
    width: 900px;
    float: left;
    height: 45px;
    background: #D9D9DC;
}

http://jsfiddle.net/CePt6/2/

EDIT

Now, if you mean the content block is moving down, make the width of the #app the same width as your #app-actionbar:

#app {
    border:1px solid #666;
    overflow: auto;
    width: 900px;
}

http://jsfiddle.net/CePt6/3/

4 Comments

There are two parts to this question: "I want to add a border around it, but its not working (and its moving the content down)."
@thirtydot - Yes, I just remembered the second part. See my last edit. ;)
I think he means he wants the content to the right of the sidebar, not underneath it.
@thirtydot - Doh! Ok, added that too.
1

Just for giggles, tried that but with some layout changes. Check if it helps. (demo here)

<div id="app">
    <div id="app-actionbar">
        topbar
    </div>
    <div id="app-userinfo">
        sidebar
    </div>
    <div id="app-content">
        content
    </div>
</div>

CSS:

#app {
    border:1px solid #666;
    clear:both;
    position:absolute;
}

#app-actionbar {
    color: #333;
    width: 900px;
    float: left;
    height: 45px;
    background: #D9D9DC;
    margin-top:0px; 
}

#app-content { 
    float: left;
    color: #333;
    background: red;
    height: 350px;
    width: 725px;
    display: inline; 

    left:200px;
    top:75px;
}

#app-userinfo { 
    color: #333;
    background:#F2F2F2;
    height: 350px;
    width: 175px;
    float: left;
    top:65px;

}

Comments

1

this should do the trick. jsfiddle.net demo

#app {
border:1px solid #666;
height: auto;
overflow: auto;
width: 900px;
}

#app-actionbar {
color: #333;
width: 900px;
float: left;
height: 45px;
background: #D9D9DC;
}

#app-content { 
float: left;
color: #333;
background: #FFFFFF;
height: 350px;
width: 725px;
display: inline;
}

#app-userinfo { 
color: #333;
background:#F2F2F2;
height: 350px;
width: 175px;
float: left;
clear: left;
}

1 Comment

You should consider adding a jsFiddle demo of your code to your answer. As the moment, I have no way to see what code renders like without expending effort, so I'm not as likely to upvote your answer.
0

Here's what you can do:

Add the following lines to your #app div like this:

width:900px;
min-height: 300px;
overflow:auto;

The above is meant to auto-expand the outer div as the inner contents increase in length.

This however will be a restriction on older versions of IE since they did not have the min-height property.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.