我怎样才能使我的文本成为带有填充和省略号的两行?

时间:2018-07-29 04:35:58

标签: html css css3 sass

我在用省略号将文本放在两行时遇到问题。我可以使用省略号,但是修改line-heightheight并不能改变显示的行数。对于为什么我无法更改行数的任何帮助都会很棒。

https://codepen.io/Joe_Scotto/pen/gjXoJy

4 个答案:

答案 0 :(得分:1)

尝试一下

CSS

.slick-slide {
  border-radius: 7px;
  height: 200px;
  margin: 0 10px;
  overflow: hidden;
  position: relative;
  width: 200px;

  img {
    bottom: 0;        
    left: 0;
    margin: auto;
    position: absolute;
    right: 0;
    top: 0;
  }

  .info {
    background: rgba(black, 0.5);
    border: 1.5px solid white;
    border-radius: 7px;
    bottom: 10px;
    color: white;
    left: 0;
    margin: 0 10px;
    padding: 7px 10px;
    position: absolute;
    text-align: center;
    right: 0;
    z-index: 1;

    h6 {
      display: -webkit-box;
      margin: 0 auto;
      overflow: hidden;
      text-align: center;
      text-overflow: ellipsis;            
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;            
    }
  }
}

DEMO

您需要做的就是将-webkit-line-clamp的值调整为希望显示的行数。

答案 1 :(得分:0)

我使用-webkit-line-clamp: 2属性更新了代码。请检查浏览器支持here,而here是密码笔

.slick-slide {
  margin: 0 10px;
  height: 200px;
  width: 200px;
  overflow: hidden;
  position: relative;
  border-radius: 7px;
}
.slick-slide img {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  margin: auto;
}
.slick-slide .info {
  z-index: 1;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  color: white;
  text-align: center;
}
.slick-slide .info h6 {
  border: 1.5px solid white;
  display: inline-block;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 7px;
  text-align: center;
  margin: 0 auto;
  max-width: 80%;
  padding: 7px 10px;
  line-height: 20px;
  height: 40px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: block-axis;
  overflow: hidden;
  text-overflow: ellipsis;
}
<div class="slick-slide">
    <div class="info">
        <h6>elements that are on fire my dude elements that are on fire my dude elements that are on fire my dude elements that are on fire my dude</h6>
    </div>
    <img src="http://placekitten.com/g/200/300" class="img-fluid">
</div>

答案 2 :(得分:0)

我的解决方法是trim all lines with clip-path,在“ ...”之后仍然可见。

clip-path: polygon(0 0, 0 calc(100% - 20px), 100% calc(100% - 20px), 100% 0);

答案 3 :(得分:-1)

.slick-slide .info {
    z-index: 1;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 15px;
    color: white;
    text-align: center;
    height: 40px;
    border: 1.5px solid white;
    background: rgba(0, 0, 0, 0.5);
    overflow: hidden;
    border-radius: 7px;
}

.slick-slide .info h6 {
    margin: 0;
    padding: 7px 10px;
    height: 19px;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    display: -webkit-box;
}