css - 如何计算 CSS minmax() 的单元格需要的最小长度?
问题描述
我正在尝试设计一些 CSS 网格。
我想将 MINIMUM 长度设置为顶部单元格需要
将其所有文本保留在一行中的空间量。例如:
<h2 id="dominantCell">This is some text</h2>
<style>
#dominantCell { /* I don't know how long the text is in one line */
grid-template-columns: minmax( /* <h2>'s width */ , 100%)
} /* How do I find out what the min should be WITHOUT counting pixels? */
</style>
我如何合理地计算这样的东西而不每次都计算像素?
解决方案
试试这个:
grid-template-columns: minmax( min-content, 100% )
或者
grid-template-columns: minmax( min-content, 1fr )
有关. _ _min-content
推荐阅读
- mysql - 如何在具有 3 次类似运算符的 SQL 查询中编写一次“替换”
- windows - 在 Windows 上可靠地暂停所有正在播放的媒体
- elasticsearch - Elastic 没有找到 1 个单词的结果
- python - 使用 Tensorflow 的目标数组形状与预期输出不同
- android - 我可以在以下代码中应用 onTap
- android - 如何访问所有 R.color 颜色或如何添加新颜色
- python - 打印函数中的双变量可能的矩阵运算
- angular - 找不到模块“流浏览器”
- c# - 控制 MouseWheel 事件时滚动导致闪烁
- django - 我如何在 django 中使用 ModelChoiceField(queryset=...) 从选项中获取选定的值