作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试 line-clamp 3 行,但由于某种原因,当我添加填充时它似乎不起作用并像这样移动到 4 行:
.title{
padding:1rem;
width:10%;
background-color:red;
word-break: break-all;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: hidden;
}
<div class='title'>
Testing Testing Testing Testing Testing Testing Testing
</div>
我该如何解决?
编辑:
抱歉,我忘了说我需要这样的底部边框:
.title{
padding:1rem;
width:10%;
background-color:red;
word-break: break-all;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: hidden;
}
.title:nth-of-type(1){
border-bottom:solid 1px black;
}
<div class='title'>
Testing Testing Testing Testing Testing Testing Testing
</div>
<div class='title'>
Testing Testing Testing Testing Testing Testing Testing
</div>
我希望我不必将它包裹在另一个 div 上
最佳答案
line-clamp
只是在设置的行之后夹住文本。但它不会从 dom 中删除文本。
例如,line-clamp: 3
结果如下:
Hello World
This is
An Exammple...
For this Post
这就是我们添加 overflow: hidden;
来隐藏它的原因。
但是填充会让你的盒子变大,所以 overflow
只会在你填充之后发生。
一种解决方案是将您的标题包装在包装器 div 中并在那里设置填充。
代码段包含一个没有溢出的示例,用于可视化
.title{
padding:1rem;
width:10%;
background-color:red;
word-break: break-all;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
<div class='title'>
Testing Testing Testing Testing Testing Testing Testing
</div>
关于html - 为什么线夹不能与填充一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70211893/
我正在使用 -webkit-line-clamp: 2 来限制 ionic4 应用程序中出现的行数,但它在初始加载时并未按预期出现。相反,当我使用 chrome 中的 inspect 编辑 css 时
我是一名优秀的程序员,十分优秀!