0

The "Style" of a SPAN applies until /SPAN.

But this does not apply to some attributes (e.g., background-color).

Which attributes don't work?

  • Is the quality I am looking for called "deprecate"?
  • Is it just background-color?
  • Is there a substitute for "background-color" that does work?

Thank you!

PS - I found a complete (?) Index of Attributes (it does not have "background-color" - although it has "bgcolor" (which "deprecates")).

<p>GDH2 no style</p>
<p  style="background-color:red; color:white; 
           font-size:140%; font-family:verdana; 
           text-align:center">
           GDH2 p style = bg color, font color, verdana, centered</p>

</span>
<span style="color:red; ">
    <p>GDH2 - inside span font color red = WORKS</p>
</span>
<span style="font-size:140%; ">
    <p>GDH2 - inside span font size 140% = WORKS</p>
</span>
<span style="font-family:verdana; ">
    <p>GDH2 - inside span Verdana = WORKS</p>
</span>
<span style="text-align:center; ">
    <p>GDH2 - inside span Verdana = WORKS</p>
</span>
<span style="background-color:blue; ">
    <p>GDH2 - inside span of bg color blue = <b>FAIL</b></p>

`

shaun
  • 1,017
  • 11
  • 22
Wood Loon
  • 25
  • 1
  • 4
  • Answered here: http://stackoverflow.com/questions/746531/is-it-wrong-to-change-a-block-element-to-inline-with-css-if-it-contains-another – regulus Apr 25 '15 at 21:04

2 Answers2

1

You can apply background-color to span

 <span  style="background-color:red; color:white; 
           font-size:140%; font-family:verdana; 
           text-align:center">
           GDH2 p style = bg color, font color, verdana, centered</span>

http://jsfiddle.net/trzk4xm2/

Prime
  • 3,530
  • 5
  • 28
  • 47
  • This is not what op is asking. The problem is related to a block element put inside an inline element. In your example it only contains text. – regulus Apr 25 '15 at 21:05
1

The html p (paragraph) won't inherit the background-color property from an inline parent (which is, btw wrong html in many lvls). Make that parent span NOT inline and you may have your color in the span... (Not in the paragraph)

Alvaro Menéndez
  • 8,766
  • 3
  • 37
  • 57