Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you indent *every* line of a <span> element?

I have the following HTML chunk:

<span class='instruction_text'>
  Line 1<br>
  Line 2
</span>

And the CSS declaration of instruction_text is:

.instruction_text {
  margin-left: 70px;
  font-style: italic;
  color: #555;
}

The first line has a 70px margin as expected, but the next line starts with no indent. How can I make ALL of the lines indented?

like image 947
Nathan Osman Avatar asked Mar 25 '10 00:03

Nathan Osman


People also ask

How do you indent text on a page in CSS?

How to Indent Text in CSS You can use the CSS text-indent property to indent text in any block container, including divs, headings, asides, articles, blockquotes, and list elements. Say you want to indent all div elements containing text on a page to the right by 50px. Then, using the CSS type selector div, set the text-indent property to 50px.

How do I insert multiple lines of text in a span?

You really should be using an element that is a "block" level element like DIV or P, e.g. one that is designed to contain multiple lines of text (or inline elements). As you'll have noticed, you CAN use a BR tag inside a SPAN and it will cause a line break, however inline elements don't play well with margins/padding etc.

How to indent the first line of a paragraph in HTML?

It can be done using an inline style inside HTML. How to indent only the first line of a paragraph? <p style = “text-indent: 40px”> This text is indented. </p> this way only the first line will be indented. In this article, we explained how you can indent using HTML and CSS.

How do I indent text in an ordered list?

An ordered list element (<ol>) will indent its list items by default. If you’d like to change the indentation distance, then you can use CSS. In this case, you won’t use the text-indent property. Instead, you’ll use the margin-left or padding-left property.


2 Answers

Use a block-level element. <div> is block-level by default, but adding the CSS display:block to your instruction_text class should send you in the right direction.

like image 150
bcherry Avatar answered Oct 05 '22 23:10

bcherry


Using BR tags inside a SPAN element doesn't make a lot of sense as SPAN in an inline element which means it's meant to be used in the flow of a line of text or other inline elements.

You really should be using an element that is a "block" level element like DIV or P, e.g. one that is designed to contain multiple lines of text (or inline elements).

As you'll have noticed, you CAN use a BR tag inside a SPAN and it will cause a line break, however inline elements don't play well with margins/padding etc.

like image 30
jonhobbs Avatar answered Oct 05 '22 22:10

jonhobbs