Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<div> background got cut

Tags:

html

css

I wanna highlight some lines in a <div>.
Some lines are longer than the width of the <div>, so I use <div style="overflow:scroll;">.
However, when I scroll to the right, the highlighted background is cut at the right edge, so text longer than the <div>'s width has no background.
enter image description here

<style>
.a { background-color:red; }
.b { background-color:yellow; }
</style>
<div style="overflow:scroll;width:49%;height:100%;border:1px solid silver;white-space:nowrap;">
<pre>
<div class="a">ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
dffdgfdsgfg</div>
<div class="b">asdsad</div>
</pre>
</div>


Can anyone fix this?

like image 591
user538565 Avatar asked Dec 29 '25 17:12

user538565


1 Answers

remove white-space:nowrap;

and add word-wrap: break-word;

like image 114
Harshit Tailor Avatar answered Jan 01 '26 10:01

Harshit Tailor



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!