


css forces line breaks and exceeds hiding to achieve single and multiple lines (code example)
The content this article brings to you is about css forced line wrapping and beyond hiding to achieve single and multi-line (code examples). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. .
<!-- white-space: normal|pre|nowrap|pre-wrap|pre-line|inherit; white-space:设置如何处理元素内的空白; word-break: normal|break-all|keep-all; word-break:用来标明怎么样进行单词内的断句 word-wrap: normal|break-word; word-wrap:用来标明是否允许浏览器在单词内进行断句,这是为了防止当一个字符串太长而找不到它的自然断句点时产生溢出现象。 text-overflow:ellipsis; 让多出的内容以省略号...来表达。但是这个属性主要用于IE等浏览器,Opera浏览器用-o-text-overflow:ellipsis; 而Firefox浏览器没有这个功能,多出的内容只能隐藏起来。 display:-webkit-box; //将对象作为弹性伸缩盒子模型显示。 -webkit-box-orient:vertical; //从上到下垂直排列子元素(设置伸缩盒子的子元素排列方式) -webkit-line-clamp:2; //这个属性不是css的规范属性,需要组合上面两个属性,表示显示的行数。 /* autoprefixer: off */ /* autoprefixer: on */解决-webkit-box-orient:vertical -->
Popular explanation:
word-break:break-all; only works in English, using letters as the basis for line breaks
word-wrap:break-word; only works in English It works in English, using words as the basis for line breaks
white-space:pre-wrap; It only works in Chinese, it forces line breaks
white-space:nowrap; It works in all cases if it forces no line breaks
white-space :nowrap; overflow:hidden; text-overflow:ellipsis; no line breaks, the excess part is hidden and appears in the form of ellipses (supported by some browsers)
Case: There are comments in the case,
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> body { width: 100%; margin: 200px 20%; } .indexBox1 { width: 60%; height: 100px; font-size: 14px; color: #ffffff; display: flex; justify-content: space-around; } /* 单行 */ .indexBox1 .box_text1 { width: 100px; height: 98px; background: gray; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; /* word-break: normal; word-wrap: none; */ } /* 多行 */ .indexBox1 .box_text4 { width: 100px; height: 98px; background: black; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-box-orient: vertical; /* Firefox */ display: -moz-box; /* autoprefixer: off */ -moz-box-orient: vertical; /* autoprefixer: on */ /* Safari、Opera 以及 Chrome */ display: -webkit-box; /* autoprefixer: off */ /*解决下面这个属性不显示*/ -webkit-box-orient: vertical; /* autoprefixer: on */ /*解决上面这个属性不显示*/ /* 控制在第几行多出的内容省略 */ -webkit-line-clamp: 5; } .indexBox1 .box_text5 { /* word-break: normal|break-all|keep-all; */ word-break: break-all; } .indexBox1 .box_text6 { /* word-wrap: normal|break-word; */ word-wrap: break-word; } </style> </head> <body> <!-- 单行 --> <p class="indexBox1"> <p class="box_text1"> 我们来自同一个世界,我们都有自己的梦想,我们都不曾放弃 我们来自同一个世界,我们都有自己的梦想,我们都不曾放弃 我们来自同一个世界,我们都有自己的梦想,我们都不曾放弃 </p> <p class="box_text1"> we are come from a world,we have us dream,wo never give up us deram; </p> <p class="box_text1"> we are come from a world,we have us dream,wo never give up us deram; </p> </p> <!-- 多行 --> <p class="indexBox1"> <p class="box_text4"> 我们来自同一个世界,我们都有自己的梦想,我们都不曾放弃 我们来自同一个世界,我们都有自己的梦想,我们都不曾放弃 我们来自同一个世界,我们都有自己的梦想,我们都不曾放弃 </p> <p class="box_text4 box_text5"> we are come from a world,we have us dream,wo never give up us deram; </p> <p class="box_text4 box_text6"> we are come from a world,we have us dream,wo never give up us deram; </p> </p> </body> </html>
-webkit-line-clamp is used to limit the number of lines of text displayed in a block element. In order to achieve this effect, it needs to be combined with other WebKit properties. Commonly combined properties:
display:-webkit-box; must be combined to display the object as a flexible box model.
-webkit-box-orient must be combined with the attribute to set or retrieve the arrangement of the child elements of the flex box object.
But in order to be compatible with the Firefox browser, it is implemented by combining css and js;
The following is the implementation process:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <style> .content { margin: 0 auto; width: 400px; line-height: 25px; margin-top: 100px; position: relative; height:auto; overflow: auto; } .contentHide{ height: 50px; overflow:hidden; } .contentHide::after { content: "..."; position: absolute; bottom: 0; right: 0; padding-left: 20px; /* background: -webkit-linear-gradient(left, transparent, #fff 55%); background: -o-linear-gradient(right, transparent, #fff 55%); background: -moz-linear-gradient(right, transparent, #fff 55%); */ background: linear-gradient(to right, transparent, #fff 55%); } </style> <body> <p class="content">我们来自同一个世界我们都有自己的梦想,我们不曾放弃;我们不曾放弃;我们不曾放弃;我们不曾放弃;我们不曾放弃;我们不曾放弃</p> <p class="content">我们来自同一个世界我们都有自己的梦想,我们不曾放弃;我们不曾放弃</p> <p class="content">我们来自同一个世界我们都有自己的梦想,我们不曾放弃</p> </body> <script> let ct=document.querySelectorAll(".content"); for(let i=0;i<ct.length;i++){ //通过高度判断是否要添加超出隐藏的class名 if(ct[i].offsetHeight>50) { ct[i].classList.add('contentHide'); } } </script> </html>
The above is A full introduction to css forced line breaks and beyond hiding to achieve single and multiple lines (code examples). If you want to know more about CSS video tutorial, please pay attention to the PHP Chinese website.
The above is the detailed content of css forces line breaks and exceeds hiding to achieve single and multiple lines (code example). For more information, please follow other related articles on the PHP Chinese website!

In a perfect world, our projects would have unlimited resources and time. Our teams would begin coding with well thought out and highly refined UX designs.

Oh, the Many Ways to Make Triangular Breadcrumb Ribbons

SVG has its own set of elements, attributes and properties to the extent that inline SVG code can get long and complex. By leveraging CSS and some of the forthcoming features of the SVG 2 specification, we can reduce that code for cleaner markup.

You might not know this, but JavaScript has stealthily accumulated quite a number of observers in recent times, and Intersection Observer is a part of that

We may not need to throw out all CSS animations. Remember, it’s prefers-reduced-motion, not prefers-no-motion.

PWA (Progressive Web Apps) have been with us for some time now. Yet, each time I try explaining it to clients, the same question pops up: "Will my users be

It's extremely surprising to me that HTML has never had any way to include other HTML files within it. Nor does there seem to be anything on the horizon that

There are a lot of different ways to use SVG. Depending on which way, the tactic for recoloring that SVG in different states or conditions — :hover,


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software