1

I know that I can use <br> for a simple line break. I also know that I can add indentation by adding styling to a <p style="margin-left:12px">.

Now I have a problem, which is that <p> breaks two lines, it is almost like inserting <br><br>.

I cannot apply styling to <br> and also am unable to figure out how to prevent the double line break from <p>.

Is there something like an element that does not break lines or similar? No matter what element I add to apply styling, they have that double line break, e.g. div.

The Look

What I want

some text
  some other text
    even more text

What I was able to achieve

This is what I get using three <p> with margin-left styling:

some text

  some other text

    even more text

This is what I can achieve with br:

some text
some other text
even more text
creativecreatorormaybenot
  • 114,516
  • 58
  • 291
  • 402

4 Answers4

1

Try using span elements with float: left; clear: both; and then use whatever margin-left you want.

Chrillewoodz
  • 27,055
  • 21
  • 92
  • 175
0

You can use this trick to achieve your goal

span{
display:block;
text-indent:12px;
}
span samp{
display:block;
text-indent:24px;
font-family:initial;
}
<p>
  Some text
  <span>
    Some other text
    <samp>Some other text</samp>
  </span>
  
</p>
0

A <p> (paragraph element) is a block-level element. This means, on default it will be positioned in a new row.

That's why you see a double linebreak.

So therefor, use inline elements like <span> to move the text to the right.

<p>some text<br/>
    <span style='margin-left:12px'>some other text</span><br/>
    <span style='margin-left:24px'>some more text</span></p>
Daan
  • 2,680
  • 20
  • 39
0

Deleting margins (margin-top and margin-bottom, most importantly) from p elements make them act like lines of text one below another and then use of <br> creates single linebreak. However if you want to add margin-left based on position of given p you can't do this without any SCSS or hard coding values for child number 1, 2, 3 and so on. Other posts on SO about same problem:

Post 1, post 2, post 3.

p {
  margin: 0;
}
<p>test test test test test test test test test</p>
<br>
<p>test test test test test test test test test</p>
<br>
<p>test test test test test test test test test</p>
<br>
<p>test test test test test test test test test</p>
Andrzej Ziółek
  • 2,241
  • 1
  • 13
  • 21