gpt4 book ai didi

html - 如何在 HTML/CSS 中将表单居中对齐

转载 作者:太空宇宙 更新时间:2023-11-03 20:38:52 25 4
gpt4 key购买 nike

我在将表单和按钮居中对齐时遇到问题,这是我的代码:

<body>
<h1 style="font-family:Comic Sans Ms;text-align:center;font-size:50pt;color:#ff00ba;">
You need to login :) </h1>

<form style="font-family:Comic Sans Ms; align:center;">
Username<br>
<input type="text" name="userid"/><br>
Password<br>
<input type="password" name="pswrd"/>
<br><br>
<input style="font-family:Comic Sans Ms;" type="button" onclick="check(form)" value="Login"/>
<input style="font-family:Comic Sans Ms;" type="reset" value="Cancel"/>
</form>
........

你可以看到我在表单样式中设置了“align:center”,但是没有用,表单和按钮仍然在网页的左侧,实际上,我试过div,它起作用了。但是,如果我不使用 div 并且我只想使用我当前的格式来设置对齐样式,有什么方法可以让它居中吗?干杯

最佳答案

使用文本对齐:居中;

JSFIDDLE

<body>
<h1 style="font-family:Comic Sans Ms;text-align:center;font-size:50pt;color:#ff00ba;">
You need to login :) </h1>

<form style="font-family:Comic Sans Ms; text-align: center;">
Username<br>
<input type="text" name="userid"/><br>
Password<br>
<input type="password" name="pswrd"/>
<br><br>
<input style="font-family:Comic Sans Ms;" type="button" onclick="check(form)" value="Login"/>
<input style="font-family:Comic Sans Ms;" type="reset" value="Cancel"/>
</form>

关于html - 如何在 HTML/CSS 中将表单居中对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29162155/

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