使文本输入出现在页面的中心而不是顶部

making a text input appear at center not at the top of the page

本文关键字:顶部 输入 文本      更新时间:2023-09-26

伙计们,我是新来的HTML…我想让这个Username: <input type="text" name="Username" style=" - margin-top: 200px; ">出现在页面的中心,而不是在顶部…我试着使位置绝对,并改变边距顶部,但我发现只有空白文本字段出现在中心和单词"用户名"仍然在顶部。有什么帮助吗??

写入div容器。别忘了设置高度和重量来设置自动居中

<div style="width:200px;height:1em;margin:auto;">Username <input type="text" name="username"/></div>

你需要用span标签包装整行。

这将允许你引用所有的文本,而不仅仅是输入。

<span style="-margin-top: 200px;">Username: <input type="text" name="Username"></span>

应该可以。

至于定位,你可能会寻找绝对居中技术。

element {
  text-align: center;
  margin: auto;
  position: absolute;
  top: 0; left: 0; bottom: 0; right: 0;
}