views:

328

answers:

2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
    <style type="text/css">       
        #textarea1 {
            width: 100%;
            overflow:hidden;
        }
        #table1 {
 background-color:#0000ff;
 width: 100px;
        }
    </style>
</head>
<body>
    <form id="form1">
    <table id="table1" >
        <tr><td><textarea  cols="0" rows="2" id="textarea1"></textarea></td></tr>
    </table>
    </form>
</body>
</html>

The textarea is not rendered correctly by ie8 in the table (it is wider than its cell). If I remove the doctype tag it renders correctly. Am I doing something stupid

A: 

cols="0" seems a bit daft. Set that to a sensible value for users without CSS.

You might want to try removing borders and padding from the textarea:

#textarea1 {
    width: 100%;
    overflow:hidden;
    margin: 0;
    border-style: none;
    padding: 0;
}

width refers to the width of the element’s content area, i.e. the area inside the margin, borders and padding

Paul D. Waite
A: 

IE, for some reason, interprets 100% width of a table cell as 100px-(padding/2), inherited from your #table1 width property. Now here's where it really screws up: the table has a default cellspacing of 3 pixels, so technically, your cell should be 94px wide, and 100% of that width should be... 94px. Instead, it's applying 100px.

If you explicitly set the width property of the table cell, it can correct it, but only after you set the cellspacing and cellpadding to 0, and the border-width of the textarea to 0.

e.g.:

#textarea1 {
width: 100%;
overflow:hidden;
margin:0;
padding:0;
border:0;
}
#table1 {
background-color:#0000ff;
width: 100px;
padding:0;
margin:0;
border-spacing:0;
border-collapse:collapse;
}
#table1 td {
width:100px;
padding:0;
margin:0;
}

The alternative, if you want normal borders around your textarea, is to define a width for the td as 100px - border-wdith*2.

Hope that helps, nd

ndorfin
Forgot to mention: Use a reset stylesheet. Solves a lot of problems like the one you're experiencing here with applied margins and padding.
ndorfin
Thanks for this, thought it wasn't entirely my fault. Isn't this a rather basic thing for a browser to get wrong?
haymansfield
Absolutely. Internet Explorer's interpretation of the Box Model has been pretty poor, but it appears to be getting better with each new release.
ndorfin