我已经尝试了多次,使用来自 Stack Overflow 的多种不同可能的解决方案来完成这项任务,但令人沮丧的是,我似乎无法将输入框居中放置在 div 中。
我的代码目前基本上是这样的:
div {
width: 100vw;
position: relative
}
h1 {
text-align: center;
}Run Code Online (Sandbox Code Playgroud)
<div>
<h1>Title</h1>
<input type='text'>
</div>Run Code Online (Sandbox Code Playgroud)
目前,“标题”这个词在屏幕中央,但输入框仍然在左侧。
有什么办法可以在div中水平居中吗?