Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why webkit line clamping does not work in firefox?

Tags:

I use this webkit line clamp, it works in Chrome, but not in Firefox. The following is the code:

{   overflow: hidden;   text-overflow: ellipsis;   display: -webkit-box;   -webkit-box-orient: vertical;   -webkit-line-clamp: 4; /* number of lines to show */   line-height: X; /* fallback */   max-height: X * 4; /* fallback */ } 

How should I make it work on Firefox as well?

like image 640
uklp Avatar asked Dec 15 '13 13:12

uklp


People also ask

Does Webkit work in Mozilla?

CSS prefixes -webkit- (Chrome, Safari, newer versions of Opera and Edge, almost all iOS browsers including Firefox for iOS; basically, any WebKit or Chromium-based browser)

How does webkit line clamp work?

The -webkit-line-clamp CSS property allows limiting of the contents of a block container to the specified number of lines. It only works in combination with the display property set to -webkit-box or -webkit-inline-box and the -webkit-box-orient property set to vertical .

What is line clamp?

The line-clamp property truncates a text at a specified number of lines. It limits the text, after you tell it the desirable number of lines, adding an ellipsis after the last word or portion of a word that is demonstrated. It is a shorthand for: max-lines. block-overflow.

What is Webkit in CSS?

The term 'webkit' is used in the CSS syntax for rendering content in Safari and Chrome browsers. Webkit code may need to be added in CSS to ensure it renders correctly on Chrome and Safari due to the lack of cross-compatibility.


1 Answers

Important Update:

As of Firefox version 68 Firefox supports -webkit-line-clamp!!

Demo snippet (caniuse)

p {    width: 300px;    border: 2px solid green;    padding: 0.5em 0.5em 0 0.5em;    overflow: hidden;    text-overflow: ellipsis;    display: -webkit-box;    -webkit-box-orient: vertical;    -webkit-line-clamp: 3; /* number of lines to show */  }
<p>When the CSS -webkit-line-clamp property is applied to a block of text (e.g., a paragraph), the text is limited to the specified number of lines (1 or more), and an ellipsis character (…) is added to the end of the last visible line. - see <a href="https://webplatform.news/issues/2019-05-17">webplatform.news</a>

Although Firefox uses the Gecko rendering Engine which uses the -moz- vendor prefix, since version 49, Firefox decided to add support for several -webkit- prefixes and WebKit-specific interfaces

Note: CSS Overflow Module Level 3 Editor's draft includes an official property line-clamp - which will likely replace the proprietary-webkit-line-clamp property.

Original Answer

You can't. -webkit-line-clamp is for browsers that use webkit. Firefox runs on gecko and uses the vendor prefix: -moz-

If you're interested - you could take a look at my answer here: a line-clamp with fade-out fallback fiddle which adds a fade-out effect workaround (instead of ellipsis) for non-webkit browsers.

like image 151
Danield Avatar answered Oct 04 '22 02:10

Danield