jQuery & CSS - Cut text by height, no truncate

2019-07-14 16:27发布

Because I want to toggle my text I need to hide a part of it.

Problem

  • My text height is going to be X or less pixels in height.
  • The height of the div depends on a sidebar height and is not as static as this demo.
  • If the letters on the last row are now truncated (se demo), I want to hide that row as well.

Look at my demo: http://jsfiddle.net/qWDLb/1/

My own thougt would be if the height could be calculated by using line-height or font sizes?

2条回答
仙女界的扛把子
2楼-- · 2019-07-14 17:18

You can determine line-height with:

$('.text').css('line-height')

This give you this height with 'px' at the end. Here is a working jsfiddle for showing 4 lines : http://jsfiddle.net/scaillerie/qWDLb/3/ .

查看更多
三岁会撩人
3楼-- · 2019-07-14 17:24

You will want to deal with EMs. Figure out the div's height, and if necessary, you can shrink the height of the DIV to hide the partial line.

http://webdev-il.blogspot.com/2011/03/how-to-convert-pixel-to-em-why-use-ems_31.html

查看更多
登录 后发表回答