gpt4 book ai didi

html - 如何在保持文本框居中的同时将错误消息移动到文本框的右侧?

转载 作者:行者123 更新时间:2023-11-28 01:34:25 25 4
gpt4 key购买 nike

我正在为我正在构建的新站点创建一个表单,但无法弄清楚如何在文本框右侧显示错误消息,同时保持文本框在屏幕上居中。到目前为止,我只能让它们出现在文本框上方,但我宁愿让它们出现在它们旁边。您能提供的任何帮助将不胜感激。

这是我的代码...

<!DOCTYPE html>
<html>
<head>
<title>Register</title>
<style>
body {
background-color: silver;
}
.welcome {
text-align: center;
font-family: "Arial";
font-size: 30px;
text-shadow: 2px 2px lightgrey;
color: white;
padding-top: 15px;
}
.form-group {
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
}
input[name=username], input[name=first_name], input[name=last_name], input[name=email],
input[name=password], input[name=confirm_password] {
border: 3px solid lightgrey;
padding: 10px;
background: white;
margin: 0 0 10px 0;
width: 250px;
outline:0 !important;
}
.help-block {
font-family: "Arial";
font-size: 12pt;
color: white;
padding-bottom: 10px;
}
input[type=submit] {
color: grey;
border: 3px solid lightgrey;
padding: 5px;
width: 100px;
text-align: center;
}
input[type=submit]:focus {
outline:0 !important;
}
input[type=submit]:hover {
background-color: #ddd;
}
input[type=submit]:active {
background-color: #aaa;
color: lightgrey;
}
</style>
</head>
<div class="welcome">
<h1>Register</h1>
</div>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="form-group <?php echo (!empty($username_err)) ? 'has-error' : ''; ?>">
<span class="help-block"><?php echo $username_err; ?></span>
<input type="text" name="username" class="form-control" value="<?php echo $username; ?>" placeholder="Username">
</div>
<div class="form-group <?php echo (!empty($first_name_err)) ? 'has-error' : ''; ?>">
<span class="help-block"><?php echo $first_name_err; ?></span>
<input type="text" name="first_name" class="form-control" value="<?php echo $first_name; ?>" placeholder="First Name">
</div>
<div class="form-group <?php echo (!empty($last_name_err)) ? 'has-error' : ''; ?>">
<span class="help-block"><?php echo $last_name_err; ?></span>
<input type="text" name="last_name" class="form-control" value="<?php echo $last_name; ?>" placeholder="Last Name">
</div>
<div class="form-group <?php echo (!empty($email_err)) ? 'has-error' : ''; ?>">
<span class="help-block"><?php echo $email_err; ?></span>
<input type="text" name="email" class="form-control" value="<?php echo $email; ?>" placeholder="Email">
</div>
<div class="form-group <?php echo (!empty($password_err)) ? 'has-error' : ''; ?>">
<span class="help-block"><?php echo $password_err; ?></span>
<input type="password" name="password" class="form-control" value="<?php echo $password; ?>" placeholder="Password">
</div>
<div class="form-group <?php echo (!empty($confirm_password_err)) ? 'has-error' : ''; ?>">
<span class="help-block"><?php echo $confirm_password_err; ?></span>
<input type="password" name="confirm_password" class="form-control" value="<?php echo $confirm_password; ?>" placeholder="Confirm Password">
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Submit">
</div>
</form>
</html>

最佳答案

试试这个解决方案

<!DOCTYPE html>
<html>
<head>
<title>Register</title>
<style>
body {
background-color: silver;
}
.welcome {
text-align: center;
font-family: "Arial";
font-size: 30px;
text-shadow: 2px 2px lightgrey;
color: white;
padding-top: 15px;
}
form{ /* added this */
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
}


.form-group {
display: flex;
flex-direction: row; /* change flex-direction to row */
align-items: center;
text-align: center;
}
input[name=username], input[name=first_name], input[name=last_name], input[name=email],
input[name=password], input[name=confirm_password] {
border: 3px solid lightgrey;
padding: 10px;
background: white;
margin: 0 0 10px 0;
width: 250px;
outline:0 !important;
}
.help-block {
font-family: "Arial";
font-size: 12pt;
color: white;
padding-bottom: 10px;
}
input[type=submit] {
color: grey;
border: 3px solid lightgrey;
padding: 5px;
width: 100px;
text-align: center;
}
input[type=submit]:focus {
outline:0 !important;
}
input[type=submit]:hover {
background-color: #ddd;
}
input[type=submit]:active {
background-color: #aaa;
color: lightgrey;
}
</style>
</head>
<div class="welcome">
<h1>Register</h1>
</div>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="form-group <?php echo (!empty($username_err)) ? 'has-error' : ''; ?>">
<span class="help-block"><?php echo $username_err; ?></span>
<input type="text" name="username" class="form-control" value="<?php echo $username; ?>" placeholder="Username">
</div>
<div class="form-group <?php echo (!empty($first_name_err)) ? 'has-error' : ''; ?>">
<span class="help-block"><?php echo $first_name_err; ?></span>
<input type="text" name="first_name" class="form-control" value="<?php echo $first_name; ?>" placeholder="First Name">
</div>
<div class="form-group <?php echo (!empty($last_name_err)) ? 'has-error' : ''; ?>">
<span class="help-block"><?php echo $last_name_err; ?></span>
<input type="text" name="last_name" class="form-control" value="<?php echo $last_name; ?>" placeholder="Last Name">
</div>
<div class="form-group <?php echo (!empty($email_err)) ? 'has-error' : ''; ?>">
<input type="text" name="email" class="form-control" value="<?php echo $email; ?>" placeholder="Email">
<span class="help-block">Error Message</span>
</div>

<div class="form-group <?php echo (!empty($email_err)) ? 'has-error' : ''; ?>">
<input type="text" name="email" class="form-control" value="<?php echo $email; ?>" placeholder="Email">
<span class="help-block">Error Message</span>
</div>

<div class="form-group <?php echo (!empty($password_err)) ? 'has-error' : ''; ?>">
<span class="help-block"><?php echo $password_err; ?></span>
<input type="password" name="password" class="form-control" value="<?php echo $password; ?>" placeholder="Password">
</div>
<div class="form-group <?php echo (!empty($confirm_password_err)) ? 'has-error' : ''; ?>">
<span class="help-block"><?php echo $confirm_password_err; ?></span>
<input type="password" name="confirm_password" class="form-control" value="<?php echo $confirm_password; ?>" placeholder="Confirm Password">
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Submit">
</div>
</form>
</html>

关于html - 如何在保持文本框居中的同时将错误消息移动到文本框的右侧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50769573/

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