Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using margin / padding to space <span> from the rest of the <p>

Ive got a block of text, and i want to write the authors name and date bellow it in small italics, so i put it in a <span> block and styled it, but i want to space the name out a little bit so i applided margin (also tried padding) to the block but it cant get it to work.

Ive made a jsfiddle of the issue - HERE

The html looks like

<p><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa omnis obcaecati dolore reprehenderit praesentium. <br><span>Author Name, Year</span> </p>  

The CSS

p       {font-size:24px; font-weight: 300; -webkit-font-smoothing: subpixel-antialiased;} p span  {font-size:16px; font-style: italic; margin-top:50px;} 
like image 985
sam Avatar asked Mar 27 '13 16:03

sam


People also ask

Can we apply margin and padding to span?

Since span tags are inline, not block elements. They can only take margin left and right, not top and bottom.

Should I use margin or padding for spacing?

Is it Better to Use Margin or Padding? Use a margin when you want to adjust the spacing of an element and use padding when you want to adjust the appearance of the element itself. Margins aren't a part of the element; padding is.

How do you add space to a span tag?

Since span elements are inline elements by default, horizontal margins are ignored for them by the spec. You can make them inline blocks (supported by most, but not all, browsers), or use padding instead of margin.


1 Answers

Overall just add display:block; to your span. You can leave your html unchanged.

Demo

You can do it with the following css:

p {     font-size:24px;      font-weight: 300;      -webkit-font-smoothing: subpixel-antialiased;      margin-top:0px; }  p span {     font-size:16px;      font-style: italic;      margin-top:20px;      padding-left:10px;      display:inline-block; } 
like image 150
Peter Rasmussen Avatar answered Oct 13 '22 00:10

Peter Rasmussen