简体   繁体   English

如何限制两行的行进方向?

[英]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.

相关问题 如何限制用户输入的数量? - How can I limit the user input in quantity? 如何使Chart JS中的两行变粗 - How can I make two of my lines in Chart JS thicker 我怎样才能使用条件语句来切换我标题的颜色? - how can i use conditional statements to switch colors of my heading? 我如何集中我的标题? - How do I center my heading? 如何将Javascript字符串放在两行上? 喜欢 <br> 用HTML做 - How can I put my Javascript strings on two lines? Like <br> does in HTML 如何在增加或减少购物车数量的同时添加移除项目并增加数量并增加价格。 电话代码 - How can I add remove items and increment the quantity and increase the price while incrementing or decrementing the quantity of my cart. code by telmo 如何在没有级别的情况下制作标题 - How can I make a heading without a level 当我对数量使用双向绑定时,如何避免更改另一个文本框? - How can I avoid changing another textbox when I use two-way binding for quantity? 如何通过按数量计算我的房产价格来计算我的数组的总价? - How can I calculate the total price of my array by calculating my property price by quantity? 查询 / Json 如何在本地存储中保存数据和标题名称? - Query / Json How can I save Data and Heading name in my local storage?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM