Home > Web Front-end > JS Tutorial > body text

How to solve the overflow of text content in div

小云云
Release: 2018-01-22 13:43:35
Original
3803 people have browsed it

Sometimes when we edit content in a div, it will overflow, so what should we do if this happens? This article mainly introduces common solutions to text content overflow in p. Has very good reference value. Come and learn together.

Due to the uncertainty of the length of the text content and the fixedness of the page layout, text overflow is often encountered. Here is a solution:

1: Specify the width and height of the text parent container, and set it beyond hiding: overflo: "hidde"

-------The disadvantage is that the last line of text is often incompletely displayed. In this case, it is recommended to use

2 when only controlling the display of one line of text: css+p to prevent text from overflowing, the excess part becomes an ellipsis, and the line is displayed, white-space:nowrap;word-break: break-all; text-overflow:ellipsis; -o-text-overflow:ellipsis; overflow: hidden;

------The disadvantage is that the Firefox browser does not perform well and will truncate , the page does not have a lot to hide, it is recommended to use

3: Use jQuery to limit the number of characters


$(document).ready(function(){
//限制字符个数
$(“.word_overflow”).each(function(){
var maxwidth=23;
if($(this).text().length>maxwidth){
$(this).text($(this).text().substring(0,maxwidth));
$(this).html($(this).html()+'…');
}
});
});
Copy after login

Related recommendations:

Overflow hiding: the most comprehensive solution to the content overflow problem using css

Summary of the content overflow problem caused by CSS floating and methods to clear the floating

jQuery implements the method of controlling text content overflow expressed by ellipsis (...)_jquery

The above is the detailed content of How to solve the overflow of text content in div. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!