Log in

View Full Version : Resolved wrap not valid in 4.01 strict



james438
05-31-2011, 02:46 AM
I am trying to validate a page using doctype

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

when I get the error that wrap is not recognized. I am also not using cols attribute either since the width is fluid. In order to get this to validate should I be using a different doctype or a css equivalent for wrap and the cols attribute?

jscheuer1
05-31-2011, 03:31 AM
I take it this is as regards the textarea tag. If so, there's no good substitute for wrap. The closest css equivalent is (for wrap="off"):


white-space: nowrap;

However, perhaps until recently (I haven't checked this in the most recent browsers yet, I'm assuming that most of them now comply) not all the browsers see it that way. The older versions still abound though. In a couple of years maybe.

I don't think there are other types of wrap that one would need to be concerned about. The two others are hard/physical, and soft/virtual. These determine how the text is transmitted to the server. I'm unaware of any css equivalents for them. As they don't affect what the user sees, there probably aren't any. I believe the default is soft/virtual in most browsers. That means that unless the user hits the enter key while typing, no line break is sent when the data is submitted, but the text in the textarea will wrap visually to accommodate its dimensions. With hard/physical wrapping, the text wraps to accommodate the dimensions, and when sent to the server retains the line breaks as seen by the user in the textarea.

As for a DOCTYPE that would support wrap? I don't think any of the standards invoking DOCTYPES do.

This is one of those few cases where somethings just fall through the cracks.

However, as far as I know, wrap still works just fine. So you're left with the option of either using it and having that one glitch in your validation, or resorting to various workarounds. I'm thinking of wrap="off" here. But it would work with the other two kinds. You can have the textarea be written using javascript. If done - say with a document.write like so:


<script type="text/javascript">
/* <![CDATA[ */
document.write('Result: <textarea id="strNote" cols="50" rows="1" wrap="off" readonly><\/textarea><br>');
/* ]]> */
</script>

That will validate to HTML 4.01 strict.

Depending upon the objective one could substitute other elements and style them as I did for the code blocks on this page:

http://home.comcast.net/~jscheuer1/side/thecrawl/

They look like textareas, but they're not.

james438
05-31-2011, 03:56 AM
Thanks for explaining. I will leave my code as is then and leave the wrap="off" attribute in.

I notice that HTML5 does allow for the wrap attribute however ref (http://www.w3schools.com/html5/tag_textarea.asp). I will probably start using it soon when HTML5 becomes more commonplace.

jscheuer1
05-31-2011, 04:25 AM
Yes but . . . in HTML 5 wrap="off" is still invalid. Only 'hard' and 'soft' are allowed.

It's my opinion that the people who make the standards just have very little sympathy for presentational attributes.

Oh, and I just did a quick test in the latest release versions of various browsers (Firefox, IE, Opera, Chrome, Safari). Only Firefox appears to not respect:


textarea {
white-space: nowrap;
}

james438
05-31-2011, 04:43 AM
If wrap is the only error then it still seems like the best option is to leave things the way they are.

I sort of wish that Firefox put a bit more effort on recognizing the w3c standards. I am not as concerned with their browser specific css.