Solved

get container div to auto fit its content

Posted on 2007-11-27
6
6,581 Views
Last Modified: 2008-06-04
I have a div containing another div. the inner div has a fixed width setting, width=814px.

I want the out div to hug the inner div. I tried <div id="outer" style="width:auto;">, but it had no effect. it is still a bit wider than the inner one. did I do this wrong?

0
Comment
Question by:bhomass
  • 3
  • 3
6 Comments
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 80 total points
ID: 20362418
Setting width:auto; (which is default) means that the div will take up the full width of the page/parent element.

If you for example use float:left; on the outer div, the width will adjust itself to the inner div.
0
 

Author Comment

by:bhomass
ID: 20362525
it seemed to have done the job. but I don't understand why.

as far as I understand, float:left lines up the div in a row, aligned to the left relative to its parent. in this case, the outter div would align itself to its parent, which is not even a div, it is a td. So what did it have the effect of shrinking the outer div to the size of the inner div? could you explain?
0
 
LVL 29

Assisted Solution

by:Göran Andersson
Göran Andersson earned 80 total points
ID: 20363799
When the div floats, it no longer tries to occupy the full width of the page (as this would totally defeat the purpose of floating). The only other information that it can base it's size on, is the size of it's contents.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:bhomass
ID: 20363829
in a round about way, it does make sense. no wonder css is one of wierdest things around.
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20363900
Sometimes things doesn't make sense until you consider the alternatives, and realise that they make much less sense. :)
0
 

Author Comment

by:bhomass
ID: 20417512
sorry to let it hang for a while. I thought I already awarded the points.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now