How to achieve omission of display beyond two lines in css

藏色散人
Release: 2023-01-04 09:34:19
Original
52273 people have browsed it

Css method to implement display omission beyond two lines: first create an HTML sample file; then define the text content in the body; finally set the attribute "-webkit-line-clamp: 2;overflow" in the style : hidden;" to achieve the effect beyond omission.

How to achieve omission of display beyond two lines in css

The operating environment of this article: Windows7 system, HTML5&&CSS3 version, DELL G3 computer

CSS realizes that the text exceeds the part and exceeds two lines. Ellipses are displayed in the excess part

. Ellipses are displayed in the excess part.

<style>
.p{
    width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
</style>
<body>
    <p class="p">
        我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本
    </p>
</body>
Copy after login

If the text exceeds two lines, ellipses are displayed in the excess part.

<style>
.p{
    width: 200px;
    word-break: break-all;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2; /* 这里是超出几行省略 */
    overflow: hidden;
}
</style>
<body>
    <p class="p">
        我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本我是一个文本
    </p>
</body>
Copy after login

Recommended study: "css video tutorial"

The above is the detailed content of How to achieve omission of display beyond two lines in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
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!