Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table in IE7 with 100% width overflowing containing div

I have a table of results inside an area div. Because I am using a fluid layout, the area div doesn't have a set width. The width of the table is set to 100%, but in IE7 it overflows beyond the containing div. Any ideas?

HTML:

<div id="area">
    <table id="results">
    </table>
</div>

CSS:

#results{
    width: 100%;
}
like image 706
dmr Avatar asked Jan 18 '11 17:01

dmr


People also ask

Is a div 100% width by default?

auto automatically computes the width such that the total width of the div fits the parent, but setting 100% will force the content alone to 100%, meaning the padding etc. will stick out of the div, making it larger than the parent. so setting the 'width' to 'auto' would be better? Yes, but that's the default anyway.

What does width 100% do in CSS?

width: 100%; will make the element as wide as the parent container. Extra spacing will be added to the element's size without regards to the parent.

Why is content overflowing the div?

Overflow happens when there is too much content to fit in a box. CSS provides various tools to manage overflow. As you go further with CSS layout and writing CSS, you will encounter more overflow situations.

How do I force a div to full width?

What you could do is set your div to be position: absolute so your div is independent of the rest of the layout. Then say width: 100% to have it fill the screen width. Now just use margin-left: 30px (or whatever px you need) and you should be done.


2 Answers

Got it! I needed to set white-space:normal for all the TDs and THs within the table.

like image 132
dmr Avatar answered Sep 25 '22 04:09

dmr


You will need to give zoom: 1 to the parent <div> of table #area { zoom: 1 }

like image 45
kcoitk Avatar answered Sep 23 '22 04:09

kcoitk