html – 避免垂直切断文本/字符

我已经限制了Bootstrap中缩略图框内文本区域的高度,但是在标题是两行或更多行的情况下,它会将文本的最后一行垂直切成两半.看这里:

http://www.bootply.com/zBXG6in5R5

由于文本框有两种字体大小(标题较大,描述较小,动态且长度不同),设置行高无济于事.溢出:隐藏不会隐藏整行文本,只会溢出溢出的部分.添加文本溢出:省略号或类似不会阻止半行显示.

我已经回顾了以前的这些帖子,但它们似乎没有提供适用于我的案例的答案:

> Can I completely hide lines of text that are half cut off?
> Sentence showing half at end of the div,overflow: hidden is cutting the sentence

我已经提到过Bootstrap,以防任何人在使用他们的缩略图类时找到解决方案,但这确实是一个更普遍的问题.有没有办法阻止切线高度发生,最好是在CSS?

谢谢!

编辑:对于那些不想要bootply链接的人,这是我的CSS:

.container {
  margin-top: 20px;
}

.thumbnail .caption h3 {
  margin-top: 8px;
  margin-bottom: 8px;
}

.thumbnail-text {
  overflow: hidden;
  height: 160px;
  margin-bottom: 10px;
}

和HTML:

    
nes Longnesciunt. Neque porro quisquam est,qui dolorem ipsum quia dolor sit amet,consectetur,adipisci velit,sed quia non numquam eius modi tempora incidunt ut labore et dolore
最佳答案
我已经写了一些非常好的jQuery来计算可见的行数,然后将其限制为该数量

$(".thumbnail-text").each(function() {
  //start with 0 height
  h=0;
  //calculate height consumed by title
  $(this).find("h3").each(function() {
    h+=$(this).outerHeight();
  });
  //calculate height left over for text
  h=160-h;
  //determine the line height of the text
  lineHeight=parseFloat($(this).find("p").first().css("line-height"));
  //determine the amount of lines that can fit in the height left for the text
  lines=Math.floor(h/lineHeight);
  //set the height of the 'p' to be the lines * lineHeight
  $(this).find("p").first().css("height",(lines*lineHeight)+"px");
});

我也改变了你的css,所以现在p元素被设置为overflow:hidden并且有margin-bottom

.thumbnail-text p {
  overflow: hidden;
  margin-bottom: 10px;
}

链接 – > http://www.bootply.com/1pZoRkUHOj

我知道这是一个特定于案例的解决方案,但解决方案背后的概念将适用于任何事情

相关文章

vue阻止冒泡事件 阻止点击事件的执行 <div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些