html - 具有动态宽度/没有宽度的 CSS 省略号
问题描述
div.title
我想使用CSS 省略号来适应lorem ipsum(...)
页面,但我想在许多分辨率上使用它,所以我不能以像素为单位对宽度进行硬编码。
首先,我已经看到了类似问题的答案,但不幸的是,它对我的情况没有帮助。我为看似简单的问题而苦苦挣扎。我有一个标题,里面有几个框,一个标题可能(但不必)很长。我很确定我需要在text-overflow: ellipsis;
这里使用。问题是因为我需要处理很多分辨率,从 HD 到 4K 最低。有没有比media-queries
为每个分辨率设置更好的主意?我想设置一个width/max-width
,不要担心 this 的兄弟姐妹div.title
,只需获得可用宽度而不会压碎整个标题。我的情况:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
overflow: hidden;
}
section {
display: flex;
align-items: flex-start;
}
.header {
display: flex;
background-color: #ccc;
}
.left, .right {
display: flex;
}
.title {
background-color: lightcoral;
color: white;
font-size: 40px;
}
.title span {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: block;
}
.c-1, .c-2, .c-3 {
height: 65px;
}
.c-1 {
background-color: tomato;
width: 65px;
}
.c-2 {
background-color: darkblue;
width: 300px;
}
.c-3 {
background-color: yellow;
width: 840px;
}
<section>
<header class="header">
<div class="c-1"></div>
<div class="left">
<div class="c-2"></div>
<div class="title">
<span>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Quae corporis unde, iure aperiam nobis odit possimus distinctio veritatis aspernatur adipisci nam velit dicta minima quod soluta rem deleniti tempore libero?
</span>
</div>
</div>
<div class="right">
<div class="c-3"></div>
</div>
</header>
</section>
解决方案
推荐阅读
- java - 如何静音 Apache OpenNLP 日志
- polymer - 如何将polymer2.x 项目转换为polymer3.0?
- path - 在角度 6 的 tsconfig.lib.json 中设置命名路径
- c# - 应用于大量数据时,SQL CLR 聚合未正确终止
- python - django {% url %} NoReverseMatch at /
- sql - 使用联合在 Sql server 中不起作用的三个 IF Exists 条件选择语句结果的组合结果
- swift - 在 swift 3 上永远不会读取演示者功能
- c# - VB 代码到 C# - 命名空间 Microsoft.VisualBasic
- content-management-system - 表达式引擎使用
- android - DJI Spark:IMUState.Callback.getAccelerometerState() 和 getGyroscopeState() 翻转传感器状态