Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

padding not working in span tag

Tags:

html

css

padding

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>
like image 486
Keegan Brown Avatar asked Feb 24 '16 02:02

Keegan Brown


People also ask

Does padding work on span?

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

Why margin is not working in span tag?

Since span tags are inline, not block elements. They can only take margin left and right, not top and bottom. See this related post, Margin-Top not working for span element?

How do you put a space in a span tag?

We can use the padding-left property in a <span> element to add spaces. For example, inside the HTML body, type the text of your desire. Where you want to add the blank space, create a <span> element and apply the style in it. Set the padding-left property to 30px .

Can we apply margin and padding to span?

The reason vertical padding /margin does not work with spans is that it's an inline element.


1 Answers

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>
like image 191
dippas Avatar answered Oct 13 '22 10:10

dippas