Keegan Brown Keegan Brown - 5 months ago 17
CSS Question

padding not working in span tag

Ok, first off I want you all to know that I have tried using the

<span></span>
tag (though maybe incorrectly).

Is there something I'm doing wrong with the
<span></span>
tag? Or is there something I need to do differently altogether?

Here is my current code to create a space without
<br></br>
:



#beforeImage span {
padding: 40px;
}

<span id="beforeImage">text</span>




Answer

2 things to fix:

  • you were applying the CSS to span of an ID selector, but you were using a span with an ID selector in your HTML.

  • span won't have padding because it is an inline element by default, so set inline-block or block

Snippet

#beforeImage {
  padding: 40px;
  display: inline-block; /* or block */
 /* demo */
  background: red
 
}
<span id="beforeImage">Foo bar</span>