search
HomeWeb Front-endFront-end Q&AHow to achieve the ellipsis effect beyond hiding in CSS

In web page layout, we often need to limit the width or height of certain elements. When the width or height exceeds the limit, how to display the text content is a very important thing. Usually, we can use the overflow:hidden attribute in CSS to limit the display of element content. However, when content is hidden, some important information may be omitted, which is unfriendly to users. Therefore, we need to use the CSS ellipsis option to let users know that the text content has been omitted.

Under normal circumstances, when the text content exceeds the limit, the default processing method of the browser is to truncate and hide the excess text. However, sometimes we need to display ellipses to tell the user that some content has been omitted. At this time, we can achieve this through the text-overflow property in CSS.

The CSS property text-overflow is used to specify how to display ellipses when text overflows the containing element. The text-overflow attribute has three values: clip, ellipsis and string.

  1. The clip value indicates that when the text overflows, the content beyond the text is hidden and the ellipsis is not displayed.
  2. The ellipsis value indicates that when the text overflows, the content beyond the text is hidden and an ellipsis is displayed at the end of the text. The
  3. string value means that when the text overflows, hide the content beyond the text and display the given string at the end of the text. For example, you can set the value to "...", then three dots will be displayed at the end of the text, indicating that some content has been omitted.

The text-overflow attribute must be used together with the overflow:hidden and white-space:nowrap attributes. Among them, white-space:nowrap indicates that the text cannot be wrapped and can only be displayed in one line. overflow:hidden indicates that when the text overflows, the excess part will be hidden.

The following is an example. We set the width of a div element to 100px, the height to 50px, and the text content is super long text. When the text overflows, we use the text-overflow:ellipsis property in CSS to display the ellipsis:

<div>这是一个超长的文本,它将会在这个div中被限制宽度和高度。</div>
.text-overflow {
  width: 100px;
  height: 50px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

In the above code, we limit the width and height of the element, and the part beyond the text will be hidden . At the same time, we set the text not to wrap and can be displayed in one line. Finally, we use the text-overflow:ellipsis attribute to display the ellipses.

Summary

CSS’s beyond-hide and ellipsis attributes are commonly used techniques in web page layout. They can effectively limit the width or height of elements and display ellipses when text overflows, allowing users to Be aware that some information has been omitted. The text-overflow attribute must be used together with the overflow:hidden and white-space:nowrap attributes to correctly implement the ellipsis display effect.

I hope this article is helpful to you, thank you for reading!

The above is the detailed content of How to achieve the ellipsis effect beyond hiding in CSS. 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
What are the limitations of React?What are the limitations of React?May 02, 2025 am 12:26 AM

React'slimitationsinclude:1)asteeplearningcurveduetoitsvastecosystem,2)SEOchallengeswithclient-siderendering,3)potentialperformanceissuesinlargeapplications,4)complexstatemanagementasappsgrow,and5)theneedtokeepupwithitsrapidevolution.Thesefactorsshou

React's Learning Curve: Challenges for New DevelopersReact's Learning Curve: Challenges for New DevelopersMay 02, 2025 am 12:24 AM

Reactischallengingforbeginnersduetoitssteeplearningcurveandparadigmshifttocomponent-basedarchitecture.1)Startwithofficialdocumentationforasolidfoundation.2)UnderstandJSXandhowtoembedJavaScriptwithinit.3)Learntousefunctionalcomponentswithhooksforstate

Generating Stable and Unique Keys for Dynamic Lists in ReactGenerating Stable and Unique Keys for Dynamic Lists in ReactMay 02, 2025 am 12:22 AM

ThecorechallengeingeneratingstableanduniquekeysfordynamiclistsinReactisensuringconsistentidentifiersacrossre-rendersforefficientDOMupdates.1)Usenaturalkeyswhenpossible,astheyarereliableifuniqueandstable.2)Generatesynthetickeysbasedonmultipleattribute

JavaScript Fatigue: Staying Current with React and Its ToolsJavaScript Fatigue: Staying Current with React and Its ToolsMay 02, 2025 am 12:19 AM

JavaScriptfatigueinReactismanageablewithstrategieslikejust-in-timelearningandcuratedinformationsources.1)Learnwhatyouneedwhenyouneedit,focusingonprojectrelevance.2)FollowkeyblogsliketheofficialReactblogandengagewithcommunitieslikeReactifluxonDiscordt

Testing Components That Use the useState() HookTesting Components That Use the useState() HookMay 02, 2025 am 12:13 AM

TotestReactcomponentsusingtheuseStatehook,useJestandReactTestingLibrarytosimulateinteractionsandverifystatechangesintheUI.1)Renderthecomponentandcheckinitialstate.2)Simulateuserinteractionslikeclicksorformsubmissions.3)Verifytheupdatedstatereflectsin

Keys in React: A Deep Dive into Performance Optimization TechniquesKeys in React: A Deep Dive into Performance Optimization TechniquesMay 01, 2025 am 12:25 AM

KeysinReactarecrucialforoptimizingperformancebyaidinginefficientlistupdates.1)Usekeystoidentifyandtracklistelements.2)Avoidusingarrayindicesaskeystopreventperformanceissues.3)Choosestableidentifierslikeitem.idtomaintaincomponentstateandimproveperform

What are keys in React?What are keys in React?May 01, 2025 am 12:25 AM

Reactkeysareuniqueidentifiersusedwhenrenderingliststoimprovereconciliationefficiency.1)TheyhelpReacttrackchangesinlistitems,2)usingstableanduniqueidentifierslikeitemIDsisrecommended,3)avoidusingarrayindicesaskeystopreventissueswithreordering,and4)ens

The Importance of Unique Keys in React: Avoiding Common PitfallsThe Importance of Unique Keys in React: Avoiding Common PitfallsMay 01, 2025 am 12:19 AM

UniquekeysarecrucialinReactforoptimizingrenderingandmaintainingcomponentstateintegrity.1)Useanaturaluniqueidentifierfromyourdataifavailable.2)Ifnonaturalidentifierexists,generateauniquekeyusingalibrarylikeuuid.3)Avoidusingarrayindicesaskeys,especiall

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

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool