How to align an indented line in a span that wraps into multiple lines?

CssHtml

Css Problem Overview


Does anyone have an idea how to align the second line?

alt text

span.info {
  margin-left: 10px;
  color: #b1b1b1;
  font-size: 11px;
  font-style: italic;
  font-weight: bold;
}

<span class="info"></span>

Css Solutions


Solution 1 - Css

display:block;

then you've got a block element and the margin is added to all lines.

While it's true that a span is semantically not a block element, there are cases where you don't have control of the pages DOM. This answer is inteded for those.

Solution 2 - Css

<span> elements are inline elements, as such layout properties such as width or margin don't work. You can fix that by either changing the <span> to a block element (such as <div>), or by using padding instead.

Note that making a span element a block element by adding display: block; is redundant, as a span is by definition a otherwise style-less inline element whereas div is an otherwise style-less block element. So the correct solution is to use a div instead of a block-span.

Solution 3 - Css

span is a inline element which means if you use <br/> it'll b considered as one line anyway.

Change span to a block element or add display:block to your class.

http://www.jsfiddle.net/tZtpr/1/

Solution 4 - Css

<!DOCTYPE html>
<html>
<body>

<span style="white-space:pre-wrap;">
Line no one
Line no two
And many more line.
This is Manik
End of Line
</span>

</body>
</html>

Solution 5 - Css

try to add display: block; (or replace the <span> by a <div>) (note that this could cause other problems becuase a <span> is inline by default - but you havn't posted the rest of your html)

Solution 6 - Css

Also you can try to use

display:inline-block;

if you would like the span element to align horizontally.

Incase you would like to align span elements vertically, just use

 display:block;

Solution 7 - Css

You want multiple lines of text indented on the left. Try the following:

CSS:

div.info {
    margin-left: 10px;
}

span.info {
    color: #b1b1b1;
    font-size: 11px;
    font-style: italic;
    font-weight:bold;
}

HTML:

<div class="info"><span class="info">blah blah <br/> blah blah</span></div>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionUpCatView Question on Stackoverflow
Solution 1 - CsschoiseView Answer on Stackoverflow
Solution 2 - CsspokeView Answer on Stackoverflow
Solution 3 - CssShikiryuView Answer on Stackoverflow
Solution 4 - CssMohammad BadiuzzamanView Answer on Stackoverflow
Solution 5 - CssoeziView Answer on Stackoverflow
Solution 6 - CssDaniel NyamasyoView Answer on Stackoverflow
Solution 7 - CsstzotView Answer on Stackoverflow