Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't this HTML work?

Tags:

html

css

webkit

I have a span text block inside a paragraph. Inside this span block I have two paragraph breaks. On webkit, the browser renders the first paragraph correctly but fails back to browser default settings on the last two. Why?

<style type="text/css">

span.post-content {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 16px;
}

</style>

<p><span class="post-content"> Some text here <p/> From here text loses style and adopts browser default <p/> same here </span></p>

This works in all browsers except Webkit based ones: chrome and safari.

like image 271
Johnsx Avatar asked Jun 23 '26 10:06

Johnsx


2 Answers

The example is invalid. Fix the errors and the problem will likely go away.

  1. A span element cannot include a p element
  2. In HTML <p/> doesn't mean what you probably think it means
  3. <p/> is not allowed in HTML Compatible XHTML
  4. In XHTML, <p> may not contain <p> (nor in HTML but the end tag is optional so <p>foo<p>bar is valid and means <p>foo</p><p>bar)

You probably want something like this (and to change the CSS to reference the changed element type)

<div class="post-content">
    <p>Some text here</p>
    <p>From here text loses style and adopts browser default</p>
    <p>same here</p>
</div>
like image 190
Quentin Avatar answered Jun 26 '26 20:06

Quentin


Maybe you can start by writing well structured HTML then see if there are any problems.

like image 43
Ben Smith Avatar answered Jun 26 '26 20:06

Ben Smith