Advertisement

09.14.2007 at 04:28PM PDT, ID: 22830340 | Points: 500
[x]
Attachment Details

How to create 100% wide text fields in strict mode

Asked by schutzerj in Cascading Style Sheets (CSS), Hypertext Markup Language (HTML), Web Development

Tags: , , ,

I have struggled really hard to find an answer to the following question but I always end up with rookie answers or suggestions to switch browser. However Im confident that there is a good solution to this problem so I turn to you.

My question is simple: How do I create a text filed which is 100% wide in strict mode.

Example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    </head>
    <body style="margin: 0;">
        <input type="text" style="width: 100%;" />
    </body>
</html>

The problem here obviously is the box-model that adds the border and padding of the text field to the width, so 100% + 6px in the case of IE. A workaround that works for Firefox, Opera and Safari is to change the box-model.

input {
    box-sizing: border-box;
    -khtml-box-sizing: border-box;
    -moz-box-sizing: border-box;
}

The problem with this approach is that it doesnt work in IE 6+ (I dont care about IE < 6). My solution so far has been to extend http://webfx.eae.net/dhtml/boxsizing/boxsizing.html to handle 100% but its very hard to get right, especially if you have many inputs on your page. Another solution is to switch to quirks mode but thats not an option.

There must be a good solution for this VERY simple problem.

Please help.Start Free Trial
[+][-]09.15.2007 at 05:12AM PDT, ID: 19897285

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.15.2007 at 08:56AM PDT, ID: 19897843

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.15.2007 at 09:42AM PDT, ID: 19897947

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.15.2007 at 05:51PM PDT, ID: 19899089

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.16.2007 at 01:07PM PDT, ID: 19901394

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.16.2007 at 01:49PM PDT, ID: 19901499

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628