Solved

How to prevent floated divs from wrapping in IE6 and above and mozilla.

Posted on 2009-07-10
2
412 Views
Last Modified: 2013-11-19
Hi

Could someone help me stop the 'divCell' in code below from wrapping when the browser is narrowed?  I need the solution to work in IE6 and above and mozilla firefox. I have a minimum width set but even the slightest narrowing of the window causes the right div to wrap below the left one.

The reason why this happens is because of this line..
.divCell
{
    width:50%;

If I set the width to say 49.9% the div does not wrap but I really would like everything to be pixel perfect.

Your help would be greatly appreciated.

Cheers
<div id="divTable">
            <div class="divRow">
                <div class="divCell">
                asdfasdf
                </div>
                
                <div class="divCell">
                asdfasdf
                </div>
            </div>
        
        </div>
#divTable
{
    width:100%;
 
    background-color:Gray;
}
.divRow
{
    width:100%;
 
    background-color:Lime;
 
}
.divCell
{
    width:50%;
    float:left;
    background-color:Green;
}

Open in new window

0
Comment
Question by:jazz__man
2 Comments
 
LVL 30

Accepted Solution

by:
Britt Thompson earned 300 total points
ID: 24825834
IE is a pain and renders the margins a bit different from other browsers. It doesn't break apart for me in FF but you can add this to your IE.css or keep it uniform for all browsers:

.divCell
{
    width:50%;
    float:left;
    background-color:Green;
    margin-right:-1px; <--ADD THAT
}

It's not as bad as changing the percentage since it will always only be 2px off.
0
 
LVL 2

Assisted Solution

by:toymachiner62
toymachiner62 earned 200 total points
ID: 24825854
There might be a better fix than this but since the background color of lime won't be visible unless you have some padding on the divCell, you can just eliminate "background-color:lime;" and add "padding:1px;" to the divRow.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

685 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