javascript - 根据显示的字数有限制高度
问题描述
目前我有水平对齐的卡片,我希望高度相等。这些卡片包含从我的 API 获取的图像、标题和段落。参考图片:
一些卡片的图像和段落比其他卡片大,这让我的对齐变得混乱。我希望能够根据高度而不是根据字数限制卡片中显示的字数,以便可以为每张卡片固定,最后一个字应该显示...如果段继续。
CodeSandBox:https ://codesandbox.io/s/sad-allen-4jsst?file=/src/App.tsx
代码:
<div className="col-lg-4 col-md-6 col-sm-6 col-12">
<div
style={{
display: "block",
marginBottom: "20px",
cursor: "pointer",
textAlign: "center",
background: "#FEFEFE",
boxShadow: "0px 4px 4px rgba(0, 0, 0, 0.25)",
borderRadius: "10px"
}}
>
<div>
<img src="blogContent.png" style={{ width: "100%" }} /> //Small Image
</div>
<div style={{ padding: "20px", textAlign: "start" }}>
<div style={{ color: "#0E2043", fontSize: "13px" }}>
Biometric Passport
</div>
<div
style={{
color: "#0E2043",
fontSize: "15px",
fontWeight: "600",
marginTop: "10px"
}}
>
Commonwealth Of Dominica Announces The Launch of its New
Biometric Passport
</div>
<div
style={{
color: "#0E2043",
fontSize: "13px",
marginTop: "10px"
}}
>
{" "}
//Small Content
</div>
<div
style={{
color: "#E3AB50",
fontSize: "13px",
marginTop: "10px"
}}
>
Read More
</div>
</div>
</div>
</div>
<div className="col-lg-4 col-md-6 col-sm-6 col-12">
<div
style={{
display: "block",
marginBottom: "20px",
cursor: "pointer",
textAlign: "center",
background: "#FEFEFE",
boxShadow: "0px 4px 4px rgba(0, 0, 0, 0.25)",
borderRadius: "10px"
}}
>
<div>
<img src="content2.png" style={{ width: "100%" }} /> //big Image
</div>
<div style={{ padding: "20px", textAlign: "start" }}>
<div style={{ color: "#0E2043", fontSize: "13px" }}>
Biometric Passport
</div>
<div
style={{
color: "#0E2043",
fontSize: "15px",
fontWeight: "600",
marginTop: "10px"
}}
>
Commonwealth Of Dominica Announces The Launch of its New
Biometric Passport
</div>
<div
style={{
color: "#0E2043",
fontSize: "13px",
marginTop: "10px"
}}
>
{" "}
// Big content
</div>
<div
style={{
color: "#E3AB50",
fontSize: "13px",
marginTop: "10px"
}}
>
Read More
</div>
</div>
</div>
</div>
解决方案
您可以将此 div 设置为 textarea ,然后您可以使用 maxlength=yourNumber 属性限制单词。此外,您必须隐藏在 CSS 边框中设置的边框:无。
为了将您的图像设置为相同的大小,您应该将 div 设置为固定大小。
像这样的东西:
<div style={{width:'30px',height:'30px'}}>
<img src="blogContent.png" style={{ width: "100%"} }/>
</div>
推荐阅读
- python - 如何在python中为oracle连接传递变量值
- xamarin.forms - Xamarin Xaml 格式化标准
- spring - Spring作为Scala的依赖注入框架
- sql - 处理来自多行的日期
- html - div 不能与屏幕宽度相同,另一个 div 不允许
- c# - ASP.NET MVC Initializer 在更新数据库期间不会为数据库播种
- ios - 使用字符替换制作有效的 JSON 字符串
- c++ - 在 C++ 中创建自己的错误处理机制
- excel - 在用户桌面上将用户表单另存为 .xlsx
- ios - 使用 Apple 商务管理 (VPP) 可以将我的 APP 分发给不同国家的客户吗?