search
HomeWeb Front-endHTML TutorialHow to use ellipsis when the number of characters displayed in html text control exceeds the limit

How to solve the problem that the number of words displayed in html text control exceeds the limit? That is, text overflow controls the number of words displayed, and table text overflow controls the number of words displayed in td.

When you see the title, you will easily think of the method of truncating the text and adding an ellipsis "...". Haha, that's it. In fact, writing this log is just to record this method, because it seems that many people still don’t remember how to deal with such a situation.

The picture below is the display effect of php Chinese website (www.php.cn) when the number of words exceeds the number and ellipsis is added

How to use ellipsis when the number of characters displayed in html text control exceeds the limit

First of all, let me explain that DIV is generally used The text in the +css container that exceeds the length will float outside the frame or expand the frame. This is generally easy to solve, but I encountered this problem today: the test page did not respond under IE6, but the test page processed normally under IE8 I was depressed when I saw overflow text. Isn't this overflow processing unique to IE? Why is IE6 not working properly? Later, I checked online and found out that it turns out that IE6 only supports overflow processing if it is written inside a DIV, and IE6 or above only supports writing it in

  • , so I wrote the same overflow processing code in DIV and It’s normal if you hit it, sweat! ! ! The following is a screenshot of my processing:
    The following is the code of the html page:

    How to use ellipsis when the number of characters displayed in html text control exceeds the limit

    The following is the rendering (it will be the same after processing):

    How to use ellipsis when the number of characters displayed in html text control exceeds the limit

    The following is the code for the above two overflow processing:

    How to use ellipsis when the number of characters displayed in html text control exceeds the limit

    The following are some processing methods on the Internet, which are worth your reference:

    General text truncation (applicable to inline and block):
    [www.mb5u.com]

    .text-overflow {
    display:block;
    width:31em;
    word-break:keep-all;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
    }

    For the definition of table text overflow:
    ww.m5u.com]

    table{
    width:30em;
    table-layout:fixed;
    }
    td{
    width:100%;
    word-break:keep-all;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
    }

    What you need to pay attention to is that this stuff only works on a single line of text. If you want to use it on multiple lines, only the first line will work. Only IE will have "..." in this way of writing, and other browsers will hide it when the text exceeds the specified width.

    In-depth study of Chinese text overflow processing in opera and Firefox:
    [Problem]
    Recently I discovered that when browsing under opera, the right half of my space becomes oversized. wide (I use the same typesetting mode as you), so that it exceeds the display range of 1024 and a horizontal scroll bar appears when the window is maximized. After deleting all modules according to the method you provided, the problem is still there Like this. I am puzzled...
    I opened a new space with another pass, using the same layout, but there is no problem under Opera!
    Is it because I tested the expanded space during the test? The space on the right, as well as adding a second html module [and then deleting it] and other operations, caused my space code to be messed up?

    [Reason]

    Compatibility issue with different browsers, to be precise, it is an issue with implementation of CSS standards by different browsers. First of all, you should know that it is not just Opera that displays abnormally, Firefox No. Since Firefox is a recognized standard browser [of course, so is Opera] and has a higher market share, Firefox is used for certification.

    [Example]

    1. Firefox does not Supports the ellipsis (...) attribute, that is, a long string will display an ellipsis. text-overflow: ellipsis;
    This can be found in the log options on the space log editing page There is an application. If you enter a very long category name and come back to edit the log, you will find that the original category name will display the first part in IE, and then directly replace it with an ellipsis. However, in browsers such as Firefox, it will display very long until it bursts. Interface framework.

    2. In Firefox, style="overflow:hidden"only works on

    instead of or

    , etc.
    3. In the fixed link part, IE browser can use the word-wrap attribute to wrap the string that exceeds the width. Specifically, once the address length of the fixed link exceeds 300px, it will automatically wrap. .bvwordwrap{word-wrap:break-word;width:300px;left:0}
    AndIn browsers such as Firefox, the word-wrap attribute is not recognized because This CSS property does not comply with the W3 standard and should be replaced by white-space:normal; so that the line breaks can be correct under FireFox and IE. Also note that spaces between words cannot be used  to replace it, otherwise it will not be able to wrap correctly.

    [Related recommendations]

    1. css solves the problem that the number of text words exceeds the display Methods of ellipsis... (single line, multi-line text)

    2. Use css to solve the problem of exceeding the number of characters in the title display

    3. Online html Free video tutorial

  • The above is the detailed content of How to use ellipsis when the number of characters displayed in html text control exceeds the limit. For more information, please follow other related articles on the PHP Chinese website!

    Statement
    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
    Beyond HTML: Essential Technologies for Web DevelopmentBeyond HTML: Essential Technologies for Web DevelopmentApr 26, 2025 am 12:04 AM

    To build a website with powerful functions and good user experience, HTML alone is not enough. The following technology is also required: JavaScript gives web page dynamic and interactiveness, and real-time changes are achieved by operating DOM. CSS is responsible for the style and layout of the web page to improve aesthetics and user experience. Modern frameworks and libraries such as React, Vue.js and Angular improve development efficiency and code organization structure.

    What are boolean attributes in HTML? Give some examples.What are boolean attributes in HTML? Give some examples.Apr 25, 2025 am 12:01 AM

    Boolean attributes are special attributes in HTML that are activated without a value. 1. The Boolean attribute controls the behavior of the element by whether it exists or not, such as disabled disable the input box. 2.Their working principle is to change element behavior according to the existence of attributes when the browser parses. 3. The basic usage is to directly add attributes, and the advanced usage can be dynamically controlled through JavaScript. 4. Common mistakes are mistakenly thinking that values ​​need to be set, and the correct writing method should be concise. 5. The best practice is to keep the code concise and use Boolean properties reasonably to optimize web page performance and user experience.

    How can you validate your HTML code?How can you validate your HTML code?Apr 24, 2025 am 12:04 AM

    HTML code can be cleaner with online validators, integrated tools and automated processes. 1) Use W3CMarkupValidationService to verify HTML code online. 2) Install and configure HTMLHint extension in VisualStudioCode for real-time verification. 3) Use HTMLTidy to automatically verify and clean HTML files in the construction process.

    HTML vs. CSS and JavaScript: Comparing Web TechnologiesHTML vs. CSS and JavaScript: Comparing Web TechnologiesApr 23, 2025 am 12:05 AM

    HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

    HTML as a Markup Language: Its Function and PurposeHTML as a Markup Language: Its Function and PurposeApr 22, 2025 am 12:02 AM

    The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

    The Future of HTML, CSS, and JavaScript: Web Development TrendsThe Future of HTML, CSS, and JavaScript: Web Development TrendsApr 19, 2025 am 12:02 AM

    The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

    HTML: The Structure, CSS: The Style, JavaScript: The BehaviorHTML: The Structure, CSS: The Style, JavaScript: The BehaviorApr 18, 2025 am 12:09 AM

    The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

    The Future of HTML: Evolution and Trends in Web DesignThe Future of HTML: Evolution and Trends in Web DesignApr 17, 2025 am 12:12 AM

    The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    EditPlus Chinese cracked version

    EditPlus Chinese cracked version

    Small size, syntax highlighting, does not support code prompt function

    MantisBT

    MantisBT

    Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

    SAP NetWeaver Server Adapter for Eclipse

    SAP NetWeaver Server Adapter for Eclipse

    Integrate Eclipse with SAP NetWeaver application server.

    mPDF

    mPDF

    mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

    MinGW - Minimalist GNU for Windows

    MinGW - Minimalist GNU for Windows

    This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.