css 尾部缩进效果

要实现尾部缩进效果,文字过多,展示查看更多按钮,点击查看更多。

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .text-spread-container {
        position: relative;
        overflow: hidden;
        height: 100px;
    }

    .text {
        color: #1f1f1f;
        line-height: 26px;
    }

    .btn {
        position: absolute;
        right: 0;
        bottom: 0;
        cursor: pointer;
        background-color: #fff;
        color: #f00;
    }

    .btn:before {
        position: absolute;
        right: 100%; 
        content: "";
        width: 16px;
        height: 22px;
        background-image: linear-gradient(270deg, #fff, hsla(0, 0%, 100%, 0));
    }
</style>

<body>
    <div class="text-spread-container">
        <div class="text">
            我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字我是一大段文字文字
        </div>
        <div class="btn">...查看更多</div>
    </div>

</body>
<script>
    document.querySelector('.btn').onclick = function () {
        const height = document.querySelector('.text-spread-container').style.height
        document.querySelector('.text-spread-container').style.height = height == 'unset' ? '100px' : 'unset'
    }
</script>

</html>
image.png
image.png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容