Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - How to add padding to wrapped text?

Tags:

css

word-wrap

How can I add padding to the left-hand side of the wrapped portion of text using CSS?

Here is an example of what it might look like if I knew where the line breaks would be:

.wrapper {
  border: 2px solid darkblue;
  padding: 5px;
}

.wrapped {
  padding-left: 10px;
}
<div class="wrapper">
  Hello, this is a<br>
  <span class="wrapped">question on</span><br>
  <span class="wrapped">stackoverflow.</span>
</div>

How can I achieve the same effect when I don't know where the line breaks will occur?

like image 410
David Callanan Avatar asked Mar 18 '26 00:03

David Callanan


1 Answers

you have the css property text-indent that give you the indent of the first line

https://www.w3schools.com/cssref/pr_text_text-indent.asp

you can mix this property with a padding on your container to have padding on lines but not the first one

.wrapper {
  border: 2px solid darkblue;
  padding: 5px;
  padding-left: 15px;
  text-indent: -10px;
}
<div class="wrapper">
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper diam at erat pulvinar, at pulvinar felis blandit. Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.Etiam semper diam at erat pulvinar, at pulvinar felis blandit. Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.Etiam semper diam at erat pulvinar, at pulvinar felis blandit. Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.Etiam semper diam at erat pulvinar, at pulvinar felis blandit. Vestibulum volutpat tellus diam, consequat gravida libero rhoncus ut.</p>
</div>
like image 128
jeremy-denis Avatar answered Mar 20 '26 18:03

jeremy-denis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!