html - 倾斜 div 容器上的文本溢出
问题描述
目前我clip-path
用于应该倾斜的容器。
.box {
height: 150px;
line-height: 150px;
text-align: center;
background: yellow;
}
#first {
clip-path: polygon(0 20%, 100% 0%, 100% 80%, 0 100%);
}
#second {
clip-path: polygon(0 0, 100% 20%, 100% 100%, 0 80%);
}
#spacing {
height: 100px;
}
<div id="first" class="box">
<p>
first container with a very very very long text. It's really long and won't fit here. Some text may disappear when the screen size gets smaller.
</p>
</div>
<div id="spacing">
</div>
<div id="second" class="box">
<p>
second container with a longer text
</p>
</div>
如果窗口变小,文本不会换行,它只会消失。
如何使文本的缺失部分出现在下一行?
您可以在此页面上找到我想做的示例
解决方案
我相信以下方法可以解决您的问题。我删除了 definedheight
和line-height
for #box
,并添加了padding: 30px 0
, 以便腾出一些空间来剪辑。现在文本行为更自然。您可以调整精确值。
.box {
height: auto;
text-align: center;
background: yellow;
padding: 30px 0;
}
#first {
clip-path: polygon(0 20%, 100% 0%, 100% 80%, 0 100%);
}
#second {
clip-path: polygon(0 0, 100% 20%, 100% 100%, 0 80%);
}
#spacing {
height: 100px;
}
<div id="first" class="box">
<p>
first container with a very very very long text. It's really long and won't fit here. Some text may disappear when the screen size gets smaller.
</p>
</div>
<div id="spacing">
</div>
<div id="second" class="box">
<p>
second container with a longer text
</p>
</div>
推荐阅读
- android - ListView 元素扩展过多
- java - JDK 17 外存 API 引发异常 - 方法引发“java.lang.UnsatisfiedLinkError”异常
- javascript - 尽管使用 200 个响应代码获取静态文件,但 Django 并未设置页面样式
- typescript - 如何使用 VS Code 扩展 API 动态突出显示变量名?
- visual-studio - 如何从 Dacpac for Azure Pipeline CI/CD 中自动排除仅开发表?
- r - 如何将 for 循环中生成的数据组合成一个散点图?
- ssms - Microsoft SQL Server 管理工作室
- html - 如何为 emscripten 制作无边框的 HTML 画布
- openshift - ECS 与 AppDynamics 的集成问题
- jpa - java.lang.RuntimeException:无法从 PreparedStatement 获取 OracleSpatial Connection 对象