I've following html:
<div class="container">
<div class="header">
<h1>
a very long long long, really very very long headline ...
</h1>
</div>
</div>
and following css:
.container{
width:200px;
}
.header h1{
background-color: #e0e0e0;
display: inline;
padding: 2px 8px;
color: black;
font-size: 16px;
font-weight: normal;
line-height: 30px;
}
The problem is, that the browser adds a linebreak because of the long header and small width of the wrapping container. Thats fine. But the padding-left will not be added to the broken second and further lines. I can do this with an negative text-indent and positive padding-left to .header. but the background-color will not be moved to left so it seems as would be there still a zero padding.
How can I change this? Any trick available?
Great greetings, Falk
word-wrap: break-word; is the current one. white-space: pre-wrap; is instead for something different! It preserves all whitespaces and linebreaks are ONLY done at \n (a linebreak in the source), <br> and as necessary to fill line boxes.
Use white-space: nowrap; or give that link more space by setting li 's width to greater values. I prevented line break in li items using display: inline; . Maybe this will also help others with similar problems. Its important to be careful with display: inline as it can have side effects.
Basic HTML Line Break Syntax You can insert line breaks in HTML with the <br> tag, which is equivalent to a carriage return on a keyboard.
Try changing display: inline;
to display: inline-block;
.
As I understand it, left and right padding on inline elements will be applied to the beginning and end of the element, regardless of whether there's any line break in between. On a block (or inline-block) element, the padding is applied to the left and right of the entire element.
See https://developer.mozilla.org/en-US/docs/Web/CSS/display for a lot more information!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With