gpt4 book ai didi

html - 表单上留下的边距会在右侧创建一个额外的空白区域

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

我已经使用 margin-left 属性定位了表单,但它添加了一个水平滚动条,在页面右侧创建了额外的空白。以下是我在上面使用的 CSS。

.form {
width:100%;
margin-left:35%;
box-sizing: border-box;
}

我怎样才能去掉右侧的空白区域?

编辑:

<!DOCTYPE html>
<html>
<head>
<title>Forms</title>
<script type="text/javascript" src="../js/script.js"></script>
<link rel="stylesheet" type="text/css" href="../css/forms.css">
</head>
<body id="formbody">
<h3 class="formheader">create a new account</h3>
<form action="#" target="_self" class="form">
<input type="text" name="firstname" class="input text" placeholder="firstname">
<input type="text" name="lastname" class="input text" placeholder="lastname">
<div class="genderholder">
<h4 class="genderheader">Gender</h4>
<label class="genderlabel">male <input type="radio" name="gender" class="input radio"></label>
<label class="genderlabel">female <input type="radio" name="gender" class="input radio"></label>
<label class="genderlabel">others <input type="radio" name="gender" class="input radio"></label>
</div>
<select class="input country">
<option>Select a Country</option>
</select>
<div class="holder">
<h4 class="dobheader">Date of birth</h4>
<select id="day" class="input day">
<option>Day</option>
</select>
<select class="input month">
<option>Month</option>
</select>
<select class="input year">
<option>Year</option>
</select>
</div>

<input type="email" name="email" class="input email" placeholder="email">

<input type="submit" name="signup" value="sign up" class="input submit">
</form>
</body>
</html>

最佳答案

我假设您正在尝试将表单置于页面的中心。如果是这样,这就是解决方案。

.form {
width: fit-content;
margin: 0 auto;
box-sizing: border-box;

}
body{
max-width:100vw;
}
<!DOCTYPE html>
<html>

<head>
<title>Forms</title>
<script type="text/javascript" src="../js/script.js"></script>
<link rel="stylesheet" type="text/css" href="../css/forms.css">
</head>

<body id="formbody">
<h3 class="formheader">create a new account</h3>
<form action="#" target="_self" class="form">
<input type="text" name="firstname" class="input text" placeholder="firstname">
<input type="text" name="lastname" class="input text" placeholder="lastname">
<div class="genderholder">
<h4 class="genderheader">Gender</h4>
<label class="genderlabel">male <input type="radio" name="gender" class="input radio"></label>
<label class="genderlabel">female <input type="radio" name="gender" class="input radio"></label>
<label class="genderlabel">others <input type="radio" name="gender" class="input radio"></label>
</div>
<select class="input country">
<option>Select a Country</option>
</select>
<div class="holder">
<h4 class="dobheader">Date of birth</h4>
<select id="day" class="input day">
<option>Day</option>
</select>
<select class="input month">
<option>Month</option>
</select>
<select class="input year">
<option>Year</option>
</select>
</div>

<input type="email" name="email" class="input email" placeholder="email">

<input type="submit" name="signup" value="sign up" class="input submit">
</form>
</body>

</html>

如果您想要针对您的代码的解决方案。通过为父元素设置 overflow-x:hidden

尝试下面的操作
.form {
width: 100%;
margin-left: 35%;
box-sizing: border-box;
}
body{
max-width:100vw;
overflow-x:hidden
}

关于html - 表单上留下的边距会在右侧创建一个额外的空白区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56924122/

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