Skip to content

前言

需要实现文本显示不超过两行,超过的两行的部分,用显示更多按钮,点击后显示展开全部文本。用html+css实现
单行效果

实现

html 部分

html
<div class="pay-info">
  <input id="onekey-payInfoCheckbox" type="checkbox" style="display: none;" />
  <p class="pay-info-text">
    <span class="pay-info-text-detail"
      >###***!!气asd asd 阿斯达阿达啊1
      3阿达阿斯达暗杀是大法官地方甘道夫古典风格的公司的暗杀撒旦防守对方是否是是防守对方斯蒂芬撒旦放。</span
    >
    <span class="pay-info-text-detail1"
      >###***!!气asd asd 阿斯达阿达啊1
      3阿达阿斯达暗杀是大法官地方甘道夫古典风格的公司的暗杀撒旦防守对方是否是是防守对方斯蒂芬撒旦放。</span
    >
    <span class="pay-info-shade"></span>
  </p>
  <label for="onekey-payInfoCheckbox" class="pay-info-text-con pay-info-text-open"
    ><span class="arrow-download"></span
  ></label>
  <label for="onekey-payInfoCheckbox" class="pay-info-text-con pay-info-text-close"
    ><span class="arrow-up"></span
  ></label>
</div>
css
.pay-info {
  position: relative;
  margin-top: 12px;
}

.pay-info-text {
  /* width: 100%; */
  position: relative;
  font-size: 14px;
  max-height: 40px;
  /* min-height: 40px; */
  overflow: hidden;
  transition: max-height 0.25s;
  color: #999999;
}
.pay-info-text-detail {
  font-size: 14px;
  line-height: 1.4;
  color: #999999;
}
.pay-info-text-detail1 {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 101;
  height: 20px;
  font-size: 14px;
  line-height: 1.4;
  color: #999999;
  overflow: hidden;
  background: white;
}

.pay-info-shade {
  position: absolute;
  right: 0;
  width: 16px;
  height: 16px;
  padding: 4px;
  background: #fff;
  z-index: 99;
}
:checked ~ .pay-info-text .pay-info-shade {
  display: none;
}

:checked ~ .pay-info-text {
  max-height: 250px; /* 一个足够大的最大高度值 */
}
.pay-info-text-con {
  position: absolute;
  right: 0;
  /* left: 0; */
  width: 16px;
  height: 16px;
  cursor: pointer;
  bottom: 0;
  text-align: right;
  padding: 4px;
  color: #000;
}
.pay-info-text-open {
  background: rgba(255, 255, 255, 0.5);
}

.pay-info-text-close {
  display: none;
}
:checked ~ .pay-info-text-open {
  display: none;
}

:checked ~ .pay-info-text-close {
  display: inline-block;
  bottom: -24px;
}