2

I works properly but putting the code through a validator (validator.w3.org) comes up with an error

Error: Element p not allowed as child of element span in this context. (Suppressing further errors from this subtree.)

<!-- mobile button -->
<a class="btn btn-warning lg hidden-sm hidden-md hidden-lg"  role="button" href="http://www.website.com">
    <span>
        <i class="fa fa-shopping-cart fa-pull-left black" aria-hidden="true"></i>
        <p class="black">Visit Store</p>
    </span>
</a>
gen_Eric
  • 223,194
  • 41
  • 299
  • 337

4 Answers4

2

See this stack overflow post: Can <span> tags have any type of tags inside them?

Essentially, because span tags are inline elements, they should only contain other inline elements, not block elements.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span

Community
  • 1
  • 1
  • Thank you for the help! I was not searching 'inline elements' term. I adjusted my code and just got rid of the span and p elements. – Neal Jones Fitch Mar 15 '17 at 18:25
1

You don't want to include a 'block' element inside of an 'inline' element. That <p> tag should likely by a span or another inline element.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
LegendaryJLD
  • 148
  • 1
  • 1
  • 9
1

Because, as the error says, <p> is not a valid child of <span>. <p> is a block level element, and <span> is an inline element. You can't have a block element within an inline element.

Either invert your two tags, or use a <span> within a <span>.

For further information, I recommend checking out the WhatWG documentation, which states that <span> tags should only be used when expecting phrasing content.

Obsidian Age
  • 41,205
  • 10
  • 48
  • 71
1

Why is it causing an error when I put a <'p'> inside of a <'span'>?

Side note: --> I had to put quotes around the paragraph tag above otherwise, it would create a line break. same applies to span tag but that would result in different behaviour.

Reasoning to the error:

Only inline elements may be contained within inline elements. span is an inline element. tags such as <p> which is block element cannot go inside inline elements.

What does this error mean?

There are rules regarding which elements can be nested inside other elements and when this is allowed to happen.

Most notably, block-level elements, such as <div>, are not allowed inside inline elements such as <span>.

This error is telling you that your markup includes a <p> element inside a <span> and that this is not allowed.

Here is a LINK that explains exactly what you have asked about the W3C validator error.

Ousmane D.
  • 54,915
  • 8
  • 91
  • 126