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

PHPz
Release: 2018-05-18 17:02:38
Original
12886 people have browsed it

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 (m.sbmmt.com) 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; }
    Copy after login

    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; }
    Copy after login

    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 withimplementation 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 ofor

    , 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 standardand should be replaced by white-space:normal; so that the line breaks can be correct under FireFox and IE. Also note thatspaces 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!

    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
    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!