Solved

CSS padding-left on span creates an indent for the first line only?

Posted on 2015-02-03
3
146 Views
Last Modified: 2015-02-03
The CSS rule

span
{
    padding-left: 3em;
}

has the effect of indenting the first line of the span. Like this:

          This is the first line of text in the span and this is indented. But, the second
line is not indented.

My Question: Why wouldn't all of the text in the span be indented 3em? Why is it that this is contained to the first line of the span?

cheers,
alex
0
Comment
Question by:alexmac05
  • 2
3 Comments
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
ID: 40587001
At a guess I would say that you are looking at text that is wrapping to the next line. <span> is an inline element. If you put display:block in the css definition it would indent all the text.

More information: http://www.w3schools.com/html/html_blocks.asp
0
 

Author Comment

by:alexmac05
ID: 40587021
So, for inline elements, padding-left would only affect the first line?
0
 
LVL 38

Expert Comment

by:Tom Beck
ID: 40587232
So, for inline elements, padding-left would only affect the first line?
There's really no first line, second line, etc. with an inline element.

Think of it this way. Text inside an inline element will print out in a straight line until it hits a boundary (edge of a block element container, browser window, etc), then it will wrap to the next line by default (unless you specify white-space: nowrap). Any styling applied to an inline element will be applied as if the contents of the element will be displayed in a straight line, the auto text wrapping is not considered. So padding-left:3em will only be applied to the beginning of the straight line.

If you add display:block to the span then it is no longer an inline element. It will now behave as a block element.

Thanks for the points.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Creating a CSS block that only applies to printing By default, all of your CSS applies to every possible view of your page - whether on screen, printed, landscape, touch-screen, or whatever.  You can, however, add CSS that only applies under certai…
When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now