html - 如何删除这些 CSS 行之间的间距?
问题描述
我正在尝试article
使用 CSS 网格创建一个组件。article
但正如您在下面看到的, ( title
、publication
和excerpt
)内的不同元素之间存在大量垂直空间。
当我为行输入固定高度时(例如grid-template-rows: 10px 10px 10px
),间距消失,但只要我想使用更灵活的东西(auto
或minmax
),间距又回来了。
如何使用可以消除垂直间距的灵活高度?
main {
display: flex;
flex-direction: column;
width: 500px;
margin: 0 auto;
}
.article {
border-top: 1px solid #FF0000;
border-bottom: 1px solid #FF0000;
display: grid;
grid-template-rows: auto auto auto;
padding: 10px 30px;
color: #414a4c;
}
.publication {
display: flex;
justify-content: space-between;
color: #757575;
<main>
<a href="#" class="article">
<div class="title">
<h2>Article title number 1</h2>
</div>
<div class="publication">
<h4>The Guardian</h4>
<h4>27 May 2021</h4>
</div>
<div class="exerpt">
<p>This is an excerpt from the article this is an excerpt from the article, etc, etc.</p>
</div>
</a>
<a href="#" class="article">
<div class="title">
<h2>Article title number 2</h2>
</div>
<div class="publication">
<h4>The Intercept</h4>
<h4>27 May 2021</h4>
</div>
<div class="exerpt">
<p>This is an excerpt from the article this is an excerpt from the article, etc, etc.</p>
</div>
</a>
<a href="#" class="article">
<div class="title">
<h2>Article title number 3</h2>
</div>
<div class="publication">
<h4>Yes Magazine</h4>
<h4>27 May 2021</h4>
</div>
<div class="exerpt">
<p>This is an excerpt from the article this is an excerpt from the article, etc, etc.</p>
</div>
</a>
</main>
解决方案
尝试在你的 CSS 顶部添加这个 -
*,*:after,*:before{
padding:0;
margin:0;
box-sizing: border-box;
}
它将重置浏览器的默认填充和边距,您可以在此处了解有关 box-sizing 的更多信息:https ://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing
代码笔: https ://codepen.io/bilal-23/pen/YzQzKGx
推荐阅读
- active-directory - 如何转义 LDAP dn 进行查找?
- python - 在 while 循环中更新 Render_template
- python - 将 spark 转换为 pandas 数据框有异常:使用基于文件的收集时不支持箭头
- go - 并行获取多个字段的模式
- javascript - jQuery Slick Slider:如何滚动不到一整张幻灯片
- web-scraping - 在 python 3.6 中使用 beautifulsoup4 抓取网站以获取产品信息
- python - Python -- 值错误:索引 968 处不支持的格式字符 ',' (0x2c)
- php - 链接到外部站点时出现相对 url 的问题
- docker - OCI 运行时失败 container_linux:345 启动容器进程导致 process_linux init 导致 rootfs_linux:58 挂载导致 perm 拒绝未知
- python-3.x - 发送接收数据不能正常工作