Solved

Keep div with nested divs from wrapping to a new line

Posted on 2006-10-23
6
956 Views
Last Modified: 2012-08-14
Experts, I have a div with three divs inside of it using float:left; and the parent div width of 100%. Then I have text inside each of the child divs. Here's the problem, depending upon the browser's width and the width of the text, the third child div will wrap to a new line. I need to do something so that the div will not wrap based upon the width of the browser. However, I need to have 100% width on the parent div so that it does take up full width of the browser.

Any ideas are appreciated!

~ C
0
Comment
Question by:clickclickbang
  • 2
  • 2
  • 2
6 Comments
 
LVL 30

Accepted Solution

by:
Steggs earned 300 total points
ID: 17788222
Greetings clickclickbang,

You could apply a min-width to the parent div that is greather than the width when the float drops. Unfortunately ie6 doesnt recognise min-width. So, this may be a solution for the future

I presume your floated divs are using % widths aswell? There must be a reason why one is dropping when the browser is resized? Are you taking into account borders and padding? For example, instead of applying padding to the floats, apply margin to their contents.

Regards
0
 
LVL 5

Assisted Solution

by:Jezcentral
Jezcentral earned 200 total points
ID: 17791043
This example shows floats in IE. As Steggs has said, they shrink to fit the available screen as you change the window size if they are set to percentage width. If you go with his suggestion that should do the trick.

However, my two pence worth is if there is anything within the divs, (perhaps an image, or a word with 20+ characters) that stops the nested divs getting smaller, then they will break to the next line. Perhaps this is what is happening?

<html>
<head>
<title>title</title>
</head>
<body>

<div style="width: 100%;">
      <div id="div1" style="width: 33%; float: left;">1</div>
      <div id="div2" style="width: 33%; float: left;">2</div>
      <div id="div3" style="width: 33%; float: left;">33333333333333333333</div>
</div>

</body>
</html>

Jezcentral.
0
 
LVL 1

Author Comment

by:clickclickbang
ID: 17791908
Thanks for your posts. Jezcentral - What should I do to gaurd against 20+ character words, etc. from wrapping to a new line?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:clickclickbang
ID: 17796130
It looks like it was the padding issue. Good catch Steggs!
0
 
LVL 5

Expert Comment

by:Jezcentral
ID: 17796247
You can't stop them wrapping to a new line unfortunately. This is normally caused by an image (like a header image) which prevents the div width from getting any smaller.

Thank you for the points, but if it was Steggs who came up the right answer, then all the points should really have gone to him. :)

Jezcentral.
0
 
LVL 30

Expert Comment

by:Steggs
ID: 17796266
I say, share the wealth

Glad you got it sorted clickclickbang, thanks for the A
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
erros on link  checking 2 42
Safari SVG Image Problem 1 19
Login area of a page 4 19
Text in block not displaying properly 2 12
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …

707 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

19 Experts available now in Live!

Get 1:1 Help Now