html - 如何限制网格单元格宽度并防止其内容溢出?
问题描述
我正在使用的生成 HTML 代码的框架输出以下内容:
body {
width: 200px; /* ignore this, this is only for demonstration purpose */
}
<div class="select-option-text" style="white-space: nowrap; overflow: hidden;">
Some very long text that should be truncated with an ellipsis if it's too long to fit
<span class="select-option-secondary-text">Always show</span>
</div>
我想要实现的是始终.select-option-secondary-text
在文本旁边可见。使用短文本,这可以正常工作,但如果文本像我的示例中那样长,它会将.select-option-secondary-text
可见区域推开。
我无法使用 flexbox 解决这个问题,但我能够使用网格达到我的要求:
body {
width: 200px; /* ignore this, this is only for demonstration purpose */
}
.select-option-text {
display: grid;
grid-auto-flow: column;
grid-template-columns: minmax(0, 1fr) auto;
}
<div class="select-option-text" style="white-space: nowrap; overflow: hidden;">
Some very long text that should be truncated with an ellipsis if it's too long to fit
<span class="select-option-secondary-text">Always show</span>
</div>
但是,第一个“单元格”仍然溢出到第二个“单元格”中。使用背景颜色并不是一个真正的选择,因为.select-option-text
它有自己的背景颜色,用 JS 以编程方式设置,我不知道那种颜色。我也不能将长文本包装成 aspan
或其他东西,因为正如我所说,这个结构是由第三方 JS 库动态创建的。
我能做些什么来防止文本溢出到下一个单元格,甚至用省略号截断它?
解决方案
如果不将文本包装在自己的元素中,显然不可能使用 CSS。
推荐阅读
- redirect - lighttpd - 重定向 IP 地址
- elixir - 授权订阅:如果条件不满足则跳过触发器
- indexing - 需要自动创建用于索引的链接列表
- sas - volatile table 和 multiset volatile table 有什么区别?
- php - 如何使用 php mysql 通过单击按钮来计算文件下载
- python - pyMel 错误?无法创建所需的 MFn
- php - Codeigniter - 返回与特定位置关联的成员
- javascript - (/\s+(\W)/g, '$1') - 如何删除空格?
- java - 为什么我无法从资源中获取文件?
- ios - 切换视图控制器时连续播放音乐 - Swift 4.2