Tuesday, July 05, 2005

Is this OK, or am I a XHTML-Terrorist

Working on converting a large content managment driven site to Valid XHTML and is trying to keep all Editorial functions as they are.

I'm parsing text from a textarea. I start by defining a paragraph and parse two or more newlines to end it and create a new paragraph. The Editors are allowed to put a picture with caption, a quote block, a fact box etc. wherever they want in the body text (and have been doing so in tens of thousands of articles that I have to keep).

Nesting a <div> inside a <p> ... </p> is not valid and I cant't force the image, qoute, factbox... to be placed outside the paragraph. The only easy solution I want to use is to put the elemts inside a inline-element such as a span, making it valid, but redefine the span to display: block;

<style type="text/css">
.float {
display: block;
float: right;
}
</style>

<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Etiam vitae sapien. Quisque dictum. Nunc orci
<span class="float"><img src="lorem.jpg" width="100" height="150" border="0" alt="alttext" />
<br />Caption
</span>
lacus, rutrum eu, elementum quis, rhoncus iaculis, risus.
Pellentesque habitant morbi tristique senectus et netus
et malesuada fames ac turpis egestas.
</p>


Is fooling the validator like this OK? Or am I terrorising the quest for a valid marked-up internet! I think it's for a good cause. The Image in this example is inline, inside a pargraph where it actually belongs if that's where the Editor put it. The blockifying done with CSS is just for layout purposes!

1 Comments:

Blogger SnoboJohan said...

Comments on identical post on Tek-Tips:

Vragabond (Programmer)
5 Jul 05 10:31
It is basically defying the purpose but I do understand what you mean. I have used similar technique before and think that there is nothing really wrong with it. As long as it looks ok in the browsers. :)

tsdragon (Programmer)
5 Jul 05 12:33
They must have had something like that in mind when they decided to create the display:inline / display:block differentiation in the first place. They could have simply allowed you to display an element or not, much like visibility, and not given you the ability to change the display style from inline to block. The fact that they DID give you that ability says, to me, that's it is OK to use it.

Tracy Dryden
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.

9:56 AM  

Post a Comment |

« Home

Powered by Blogger Weblog Trackback by HaloScan.com