views:

958

answers:

5

Hey People,

I'm starting to pull my hair out of my head...

I have the following:

<html>
<head>
<style>
    body { margin:0 auto; }
</style>
</head>
<body>
    <div style="border: solid 1px red; width: 100%;">test</div>
</body>
</html>

This works in IE producing a nice div, 100% width, no H scrollbar...

Now in Chrome and FF, it is 1px wider than the window, causing an H scrollbar...

Why is that? What SHOULD I be using instead?

Thanks a lot! Albert

EDIT:

I added div { margin: 0; } to the head and removed the width: 100% and it worked, thanks.

A: 

You forgot to disable the div's margin.

Scavenger
A: 

replace the width:100% by margin:0px

Mironline
+1  A: 

As scavenger already pointed out. The margin of the div ist the problem. Reset everything with this command:

<style>
  * { margin:0; }
</style>

For more information I recommend you to read this article by Eric Meyer about reseting the CSS in all browsers to the same default values.

Raffael Luthiger
+2  A: 

The border is sitting outside of the width, so you get 100% + 2px. Just drop the width property – a div is per default 100% wide.

toscho
A: 

I still had issues with this, in the end, I added a style="zoom: 1;" to the divs

<div style="zoom: 1;">
    <div style="zoom: 1;">
        <table style="width: 100%"...
        ...
        </table>
    </div>
</div>

http://stackoverflow.com/questions/139000/div-with-overflowauto-and-a-100-wide-table-problem

Albert