How do you wrap long words on newline, and avoid horizontal scroll using CSS?
word-wrap: break-word
https://developer.mozilla.org/en/CSS/word-wrap
How to print wrapped text without horizontal scrollbar using bootstrap?
You need to break word (using word-break
rule) to avoid horizontal scroll. By default long words without any space will not break/wrap to next line. Please see below example.
Since you are already using bootstrap you can avoid the custom class below and use bootstrap class text-break
(documentation) instead of the custom class in example.
I have done 2 changes.
- Added a new class
- Removed class
row
which in your case dont need. You can have it but there should be a childcol
orcol-*
class.
.break-word {
word-break: break-all;
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<div class="container">
<div class="row h-100" style="overflow-y:scroll; padding-left:17px; padding-right:17px">
<div class="row flex-nowrap">
<div class="col">
<div class="break-word">
https://www.whitebyte.info/programming/css/how-to-make-a-div-take-the-remaining-height
TESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTE
</div>
<div>
sfdfsfdsdfdf
</div>
</div>
<div class="col-auto">
TEST Container
asddasdsaasdda
</div>
</div>
</div>
</div>
Scroll horizontally and don't drop to the next line
Using flex, display: flex
, will align horizontally your content (use flex-direction: column
for vertical).
div{ overflow-x:scroll; overflow-y:hidden; display: flex;}
div img { margin: 2px;}
<h1> Before </h1><div><img src='http://via.placeholder.com/100x100'><img src='http://via.placeholder.com/100x100'><img src='http://via.placeholder.com/100x100'><img src='http://via.placeholder.com/100x100'><img src='http://via.placeholder.com/100x100'><img src='http://via.placeholder.com/100x100'><img src='http://via.placeholder.com/100x100'><img src='http://via.placeholder.com/100x100'><img src='http://via.placeholder.com/100x100'></div><h1> After </h1>
Line breaks and horizontal scrolling in html/css
The text inside the div will wrap to fit the div width when necessary. You can prevent this setiing white-space:nowrap;
. See white-space.
Here you have an example https://jsfiddle.net/nmagq349/
Make text inside textarea not break to next line
You can do this by applying the css - white-space: nowrap
rule.
textarea {
white-space: nowrap;
}
<textarea></textarea>
Related Topics
Different Timing Functions for Different Parts of CSS3 Keyframe Animation? (Accurate Bounce)
Change All Variable Value Based on Body Class
Custom Checkboxes Failing on Firefox
Browser as a Design Tool - Change Colors, Save Them
Scale Image with CSS to Both Width and Height to Scale
How to Style Qpushbutton's Checked State to Remove Grey Dots
CSS Spread <Li> Horizontally Across <Ul>
How to Use Data Attributes with Font Awesome
Make HTML5 Video Poster Be Same Size as Video Itself
How to Style HTML5's Range Control
Jquery-Ui Datepicker CSS Problem
How to Use Both Rel="Preload" and Rel="Stylesheet" for the Same Tag
How to Change Img Src Attribute Using CSS
Why Does Fixed Positioning Alter the Width of an Element
How It Works CSS Font-Weight Values
Image Button Displaying 'Submit Query' Over the Top of Image in Firefox