中心文字到底部的网格区域
我对HTML和CSS有点陌生,但我正在尝试学习网格。我有WPF的背景,该背景大量使用网格。它主要是简单的,但我对如何对齐该区域的底部感到困惑。
AccountBar.js
<div className={styles.container}>
<img className={styles.avatar} style={{backgroundImage: `url(${profileURL})`}}></img>
<text className={styles.username}>Username</text>
<text className={styles.discriminator}>#1337</text>
</div>
style.module.css
.container {
display: grid;
grid-template-areas:
'avatar username'
'avatar discriminator';
}
.avatar {
grid-area: avatar;
background-image: url('https://tenor.com/view/pigeon-pidgeon-fire-eyes-burn-gif-24781901.gif');
background-size: cover;
border-radius: 50%;
width: 100px;
height: 100px;
border: 3px solid #591496;
}
.username {
grid-area: username;
color: white;
}
.discriminator {
grid-area: discriminator;
color: white;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您的问题不是来自网格,而是来自元素对齐。您可以添加
保证金 - top:auto;
(添加顶部边距以覆盖所有上空空间并将您的文本推到底部).username
,这将帮助您完成诡计。I think your problem is not from the grid but from element alignment. You can add
margin-top: auto;
(adding a top margin to cover all upper space and push your text to the bottom) to.username
which would help you do the trick.这里的一些解决方案:
简单的解决方案:
因为您正在使用
display:grid
setalign-fell:flex-end
in.username
SET
保证金顶:auto
in.username
复杂的(不一定需要使用这些)
使用
显示:网格
and对齐content:flex-end
in.username
使用
显示:Flex; flex方向:列
and合理 - 符合:flex-end
in.username
inA few solutions here:
Easy ones:
Because you are using
display: grid
setalign-self: flex-end
in.username
Set
margin-top: auto
in.username
Complex ones (not necessarily need to use these)
Use
display: grid
andalign-content: flex-end
in.username
Use
display: flex; flex-direction: column
andjustify-content: flex-end
in.username