View Full Version : Problems with br

frode frank
02-11-2011, 05:24 PM
Iíve been finishing up a pretty long epub book, and somewhere along the line my <br />ís suddenly stopped working as expected. I tried Threepressí validation service, and it turned up some errors. Most of them were easily fixed, but I keep getting:

ERROR: Pave Johanna.epub/content/kapittel2.html(57): element "br" from namespace "" not allowed in this context

And A LOT of them. I donít know if this has something to do with why theyíre not working as expected, but from what Iíve read here and elsewhere the problem should be fixed with a strict doctype setting. Problem is, it doesnít help.

Iíve attached the .epub in question, and really hope someone can help me out. I suspect this is some stupid little error that causes a landslide of other errors.

02-11-2011, 06:29 PM
In kapittel2.html, there are a bunch of br tags without a space before the closing slash. Maybe that's it?

frode frank
02-11-2011, 06:38 PM
Thank you. I fixed that, but it doesn’t help with my problem.

02-11-2011, 07:00 PM
I think in some species of XHTML, <br /> tags must always be inside other parent elements, so if <br /> is just sitting by itself, consider changing it to <p><br /></p> -- though I think you must also consider whether you really shouldn't instead simply add to the margins either below the previous paragraph or above the next paragraph in such cases (e..g, margin-bottom: 2ex; for the CSS for the paragraph above).

02-11-2011, 08:04 PM
frabjous nailed it - the <br/> tags are all sitting uncontained, rather than being inside a block level element such as P or DIV or a heading (H1, H2, etc). At the moment, the structure is kind of like this:

<p> ...stuff inside the P element... </p>
<p> ...stuff inside next P element... </p>

The <br/> tag needs to be inside a block level element to be valid in XHTML Strict. You could either move it inside the preceding P element, or, as frabjous suggested, get rid of the <br/> and amend the CSS formatting to increase either the bottom margin of the preceding P or the top margin of the following P.

02-11-2011, 08:13 PM
In kapittel2.html, there are a bunch of br tags without a space before the closing slash. Maybe that's it?

Just a minor "for info" on this - tags like BR which use a closing slash are valid XHTML with or without the space before the closing slash. The only reason for including the space is for backwards compatibility with browsers or other display applications that aren't XHTML compatible - they barf on the closing slash unless it's separated from the rest of the tag content by that space. If that kind of backwards compatibility isn't required, then it shouldn't matter if the space is included or not. The presence or absence of the space certainly shouldn't have any effect on validation.

Just thought I'd mention it, since I see the issue of that space before the closing slash come up every now and then in the forums.

frode frank
02-11-2011, 08:21 PM
Yeay! Working and valid. Thanks!