Solved

get container div to auto fit its content

Posted on 2007-11-27
6
6,582 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CSS z-index issue 3 31
would like the bottom of this page to be smaller 3 27
Remove lines by logo 2 29
Overlap photo won't go all the way to the right 1 17
When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
This is a how to build your own CSS3 slideshow and when I say CSS3 I mean just CSS with no javascript in sight! There a few examples online of how to do this but most just show you an example without any explanation, others make it more complicat…
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…

816 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

10 Experts available now in Live!

Get 1:1 Help Now