How do i make two lines of text in css?
The best one I've seen which is CSS only and responsive comes from Mobify Developer Blog - CSS Ellipsis: How to Manage Multi-Line Ellipsis in Pure CSS: Show
JS Fiddle Example CSS:
Html: Trimming lines of text in CSS has always been an issue in web development. Up until a few years ago, trimming lines could only be done by server-side languages or with JavaScript because CSS didn’t have a text trimming feature. One-Line TrimmingIn 2007 the first support for trimming with CSS came
to Internet Explorer 7 (in that period IE was the major browser), with the CodePen Trimming One Line with CSS h2{ text-overflow: ellipsis; resultMulti-Line Trimming with the First Version of the Flexbox ModuleIn 2012, with the first implementation of CSS Flexbox in Chrome, came the first support of multi-line trimming of text. It looked promising, and we web developers thought that this was the beginning of the end of needing server-side or JavaScript manipulations for trimming multi-line paragraphs. .line-clamp { But the joy was short lived. The CSS Flexbox module was updated twice more, after which there weren’t any traces left of the multi-line feature that was introduced with the first implementation of CSS Flexbox. For many developers - like me - who were using this feature, which was supported only by an old unofficial CSS Module, these updates felt like they were the death of the multi-line trimming feature. A history of CSS flexbox versions: display: box; /* old syntax from 2009 */ Line-Clamp Comes Back From the DeadIn July 2015, the Edge browser decided to support the In July
2019, it happened again! This time it was the Firefox browser who decided to support this feature. Here too, in the same unusual manner of These two main browsers, with two different browser engines — Mozilla's Moz & Microsoft’s Edge, decided to use an old feature from an Webkit browser. Desperate times call for desperate means, and since using the The Unofficial Line-Clamp Becomes OfficialThe fact that such primary browsers as Firefox & Edge started supporting the unofficial How Line-Clamp WorksUsing
.content p{ Line-clamp resultCodePen Live Example of Line-Clamp Combining the Old and New Methods Using a Sass MixinNow we have two ways of trimming text via CSS: the Ellipsis method for only one-line of text, and the line-clamp property for multi-line text trimming. I prefer the old way — using the ellipsis — whenever possible, because it’s closest to the official way in CSS. In light of that, I created a If the mixin gets passed a number, it will use the multi-line clamp method. If it doesn’t receive any parameter, it will use the one-line trim with the ellipsis method. It’s an overloading function. @mixin trim($numLines: null){ We can use this mixin, in two different ways: .foo{ CodePen Full Sass Mixin Example An Example Result for the Browser Support for Line-ClampBrowser support is very wide, reaching almost 95% of the browsers in the world. If line-clamp doesn’t work in the browser, it just won’t trim the text. This fallback is good enough for non-supporting browsers. Final WordsThat’s all. You can follow me via Twitter and LinkedIn. More of my CSS
posts: Who Am I? You Can find me in my Facebook groups: How do I make multiple text lines in CSS?How Line-Clamp Works. Define the old CSS Flexbox property display: -webkit-box; on a text container.. Define the number of lines of text to be displayed. Do so by using the. ... . Add the old flex-direction property from the old flexbox, -webkit-box-orient: vertical; .. Define the element with the overflow: hidden; property.. How do you put two lines of text in HTML?To add a line break to your HTML code, you use the
tag. The tag does not have an end tag. You can also add additional lines between paragraphs by using the tags. How do I display text on multiple lines?Click the Display tab. To enable multiple lines of text to be typed in the text box, select the Multi-line check box, and then optionally do one of the following: To prevent users from being able to insert paragraph breaks in the text box by pressing ENTER, clear the Paragraph breaks check box.
How do you do a line break in CSS?A line-break can be added in HTML, using only CSS, by employing the pseudo-class ::after or ::before . In the stylesheet, we use these pseudo-classes, with the HTML class or id, before or after the place where we want to insert a line-break. In myClass::after : Set the content property to "\a" (the new-line character).
|