[英]How can I limit my heading by the quantity of two lines?
I have a grid of posts width the content like this: 我有一个帖子网格宽度的内容是这样的:
<img src="/" alt="Logo">
<h3>Heading</h3>
<p>Description</p>
<div>Date</div>
And if my post's heading has more than two lines, I would like to clip it and in the end of the second line print ellipsis. 如果我的帖子标题多于两行,我想将其剪裁,并在第二行的末尾打印省略号。
Any ideas? 有任何想法吗?
You can use a display:-webkit-box
along with -webkit-line-clamp: 2;
您可以使用display:-webkit-box
和-webkit-line-clamp: 2;
, it will avoid displaying more than 2 lines in your heading. ,这样可以避免在标题中显示多于2行。
Note: 注意:
Note that it has some cross-browser issues but it's something you can go with, at the moment. 请注意,它存在一些跨浏览器的问题,但是您现在可以使用它。
CSS: CSS:
#myHeading {
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
display: -moz-box;
-moz-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
Demo: 演示:
#myHeading { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; display: -moz-box; -moz-box-orient: vertical; overflow: hidden; text-overflow: ellipsis; }
<img src="/" alt="Logo"> <h3 id="myHeading">Heading id d yz eee,zbez, zeze e ee e, e,ze, e,zaezjhezeze zaez ezae e zazejzaee je zaje zaj ezae ze ejeazezaje ej j ezaje zaej azej ejjzejze je zaeje eze zjeezejzadsdofdspflf dsufofod fdofds fdf fo dfofo udfodsfdHeading</h3> <p>Description</p> <div>Date</div>
Depending on your required level of support the CSS only line-clamp
approach may be suitable. 根据您所需的支持级别,仅CSS line-clamp
方法可能适用。
If not, then there is a small JS library available to do this called Succinct . 如果没有,那么可以使用一个名为Succinct的小型JS库来进行此操作。 There is a demo here - just scroll down when the page loads. 有一个演示在这里 -只是向下滚动页面加载时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.