gpt4 book ai didi

html - 在 div 元素内居中放置一个 H2

转载 作者:太空宇宙 更新时间:2023-11-04 15:15:30 25 4
gpt4 key购买 nike

我想将 h2 置于 #top 的中心,但是 vertical-align:middle 不起作用...我不知道该怎么做!

#top {
display: block;
position: relative;
height: 100px;
background-color: rgba(89,144,222,.6);
}
#top h2{
text-shadow: 2px 2px black;
text-align: center;
color: white;
font-family:"Impact";
font-size: 50px;
}

效果是 - http://puu.sh/2mz5M

最佳答案

我明白了,您为 div 定义了高度,这对这种情况非常有用。你可以这样做:

#top h2{
text-shadow: 2px 2px black;
text-align: center;
color: white;
font-family:"Impact";
font-size: 50px;
line-height: 100px;
}

关于html - 在 div 元素内居中放置一个 H2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15606221/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com