html - 如何使 div 只显示前 50 个字符 css
问题描述
我试图让我的卡选项条款只显示前 100 个字符,但我遇到了我添加的这 3 行代码对我不起作用的 css 问题:
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
这是我的代码库:
<div className="LoanReviewCard">
<p className="subHeader-text">BASICS</p>
<p className="header-text">
{currentLoanRequest.loanProposalDetails.purpose}
</p>
...
<p className="review-text">
<span className="bold">Optional Clause:</span>{" "}
{currentLoanRequest.loanProposalDetails.addLoanClause.length > 0 ? (
currentLoanRequest.loanProposalDetails.addLoanClause
) : "None"}
</p>
</div>
css 文件:
.review-text {
font-family: "Poppins", sans-serif;
font-weight: 400;
.bold {
font-family: "Poppins", sans-serif;
font-weight: 700;
}
font-size: 15px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
white-space: initial;
word-break: break-word;
}
问题行字太长,只想显示前 50 个字符
解决方案
var string = $('.str').text();
var str50 = string.substr(0,50)
$('.str').html(str50+'...'+'<a class="readmore" href="#">readmore</a>');
$('.str').attr('data-text',string);
$('.readmore').click(function(e)
{
e.preventDefault();
$(this).parent().html($(this).parent().attr('data-text'))
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class='str'>
How To Display 1st 50 characters Of Text by using , html, css, javascript, jquery . and after 50 charecters create link for show the total text
</div>
推荐阅读
- c# - WPF TextBox 绑定到 StringBuilder 以模拟控制台性能
- java - 如何从 servlet 获取 JSP 中的属性?
- javascript - 清除现有对话框
- reactjs - 应用程序在 heroku 上运行良好,除了一个问题
- amazon-web-services - 获取 AWS 机器类型(ubuntu/nixos/centos 等)
- browser - 屏幕阅读器在按下按钮或链接时使用什么浏览器事件?
- java - JPanel paintComponent() 不会在 JFrame 中绘制
- apache-flink - 理解 Flink 中使用的 Status.JVM.Memory.Direct.Memory
- php - PHP 错误处理程序抛出未被捕获的异常
- python - 具有名称属性的熊猫数据框