如何让列表元素内的文本与下方对应文本对齐?
解决列表项内文本列不对齐的问题

你说得对,justify-content: space-between就是问题根源——这个属性会根据每个<h3>的内容宽度动态分配元素间的空白,导致不同行的同位置元素无法对齐。下面给你两种实用的解决方法:
方案1:Flex布局下固定列宽
给每个<h3>设置统一宽度,确保每一列的占位一致,这样space-between就能让它们对齐:
li { list-style-type: none; background: cornflowerblue; margin: 50px auto; padding: 5px 10px; border-radius: 10px; display: flex; align-items: center; width: 1000px; justify-content: space-between; } /* 给每个h3设置固定宽度,可根据需求调整数值 */ li h3 { width: 180px; text-align: center; /* 可选,让文本居中更整齐 */ } ul { margin-left: 0; padding-left: 0; }
方案2:改用Grid布局(更推荐)
Grid布局天生适配这种行列对齐的场景,代码更简洁,无需手动计算宽度:
li { list-style-type: none; background: cornflowerblue; margin: 50px auto; padding: 5px 10px; border-radius: 10px; display: grid; align-items: center; width: 1000px; /* 分成5个等宽列 */ grid-template-columns: repeat(5, 1fr); gap: 10px; /* 可选,设置列之间的间距 */ } ul { margin-left: 0; padding-left: 0; }
另外提个小细节:你最后一个<h3>用了:href属性,但<h3>不是可点击的链接元素,改成<a>标签才能实现跳转功能:
<a :href="project.link">GAME LINK</a>
内容的提问来源于stack exchange,提问作者Tom W
相关产品推荐
相关产品推荐

