I have a DIV element with fixed width having some text which doesn't have any spaces for HTML parser to automatically break into multiple lines. The text is going beyond the limit of the DIV and messing out the pgae:
Regards,
Rafid
A text-overflow property in CSS is used to specify that some text has overflown and hidden from view. The white-space property must be set to nowrap and the overflow property must be set to hidden. The overflowing content can be clipped, display an ellipsis ('…'), or display a custom string.
The default value of overflow is visible . With this default, we can see content when it overflows. To crop content when it overflows, you can set overflow: hidden . This does exactly what it says: it hides overflow.
This type of problem occurs due to the following reasons, The height of the container may fixed, in this case you may set the height to auto or you may use min-height; If you want fixed height then you may set the overflow to scroll or hide. check the margin, padding and set the width properly.
You can do this with CSS.
Is there anyway to make text going beyond the boundary invisible?
Yep: overflow
#yourDivId {
overflow: hidden;
}
Is it possible to break it into multiple lines
Yep: word-wrap
#yourDivId {
word-wrap: break-word;
}
The answer to your first question is to use the following style:
overflow: hidden;
Alternatively, if you want to be able to scroll in the div to see the content you can do
overflow: auto;
or
overflow: scroll;
To do what you ask in your second question you'd need some javascript.
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