css - 文本末尾的网格模板列
问题描述
与CSS:
display: grid;
float: left;
gap: 18px;
grid-template-columns: repeat(2, 1fr);
margin-top: 10px;
有没有办法缩短Text1和Text2 long bla开头之间的距离......?(例如使用网格css而不是matgin:-12px)它们之间的距离似乎是Text2 long bla的宽度......(这是最长的元素)?
谢谢你!
解决方案
使用repeat(2, 1fr)
会将容器分成2 等份。所以如果你想降低它们之间的距离,你应该改变你的容器的宽度。
.firstContainer {
display: grid;
grid-template-columns: repeat(2, 1fr);
width: 300px;
border: 1px solid red;
}
.secondContainer {
display: grid;
grid-template-columns: repeat(2, 1fr);
width: 200px;
border: 1px solid green;
}
<section class="firstContainer">
<span>Hello</span>
<span>, World!</span>
</section>
<section class="secondContainer">
<span>Hello</span>
<span>, World!</span>
</section>
推荐阅读
- c# - 模拟 Redlock.CreateAsync 不返回模拟对象
- flutter - 如何将时间映射到动态用户事件
- python - 在 Pandas 的整个数据框上应用用户定义的函数
- humio - 如何在比赛结束后请求 humio 显示下一行?像 grep -A 1
- c# - 捕获到错误 MQException:2059 - MQRC_Q_MGR_NOT_AVAILABLE .Net Core Linux Docker Container IBM MQ,由 cipherspec 不匹配引起
- php - 创建和下载包含多个文件的 zip,而不在服务器上保存 zip 文件(PHP 和 laravel)
- git - 尽管我在 .gitignore 和 `.git/info/exclude` 中排除了特定的自动生成文件,git 并没有停止跟踪它
- node.js - React Js 17 -TypeError:执行 useParams() 时对象不是函数;
- r - mutate 和 case_when 可变数量的变量时的替代代码
- mysql - 在 sql 查询中无法识别数字数据类型