1

I need a paragraph with a space to take up space.

This fiddle shows that a space renders just the same as nothing at all:

<p class='p1'>1</p>
<p class='p1'>2</p>
<p class='p1'> </p>
<p class='p1'>4</p>

How can I achieve this effect?

  • 1
    keep in mind that it is also is considered invalid HTML to have multiple elements with the same `id`, you should use classes instead – Nick Parsons Jun 15 '19 at 04:08

3 Answers3

2

Use a non-breaking space.

<p class='p1'>1</p>
<p class='p1'>2</p>
<p class='p1'>&nbsp;</p>
<p class='p1'>4</p>
Matt Schlosser
  • 874
  • 6
  • 17
1

You can add height: 20px to your id

https://jsfiddle.net/viethien/L2eoyxhn/

If you dont want to put height, the best way is adding &nbsp; in your tag

Another way, you can add :after for #p1

#p1:after {
    content: '\200b';
}

https://jsfiddle.net/viethien/L2eoyxhn/7/

Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62
0

I do not think this <p id='p1'> </p> is a good pattern, my solution is create many class with different space

p {
  border: 1px solid black;
}

.space-medium {
  margin-top: 50px;
}

.space-low {
  margin-top: 20px;
}
<p id='p1' class="space-low">1</p>
<p id='p2' class="space-low">2</p>
<p id='p4' class="space-medium">4</p>