我尝试使用float,overflow,clear,但我的html表单仍然继续正确浮动。我的预期结果是,当我去填写表单时,html表单可以在移动设备上保持纵向显示。
这是我的html表单的当前代码:
<form name = "CommentsForm" action ="Actionpage.php" onsubmit="return
validateForm()" method="post">
<u class = "FormHeading">Send Comment</u><br>
<br>
First Name:<br>
<input type="text" name="firstname">
<br>
<div style = "position: relative; top: 4px; left: 01px;">
Last Name:<br>
<input type="text" name="lastname">
</div>
<br>
<div style = "position: relative; top: -13px; left: 1px;">
Email:<br>
<input type="text" name="email">
</div>
<br>
<div style = "position: relative; top: -24px; left:03px;">
<label for="comment"> Comment:</label></div>
<textarea id="comment" name="comment" placeholder="Type commment
here" style="height: 69px;">
</textarea>
<br>
<br>
<input type="submit" name ="submit" value="Send" >
</form>
这是我的移动网站上html表单的CSS:
form
{
border: 10px solid #D3D3D3;
border-radius: 4px;
background: #D3D3D3;
width: 176px;
height: 319px;
position: absolute;
top: 620px;
left: 91px;
font-family: "Arial", "Times New Roman", "Sans Serif";
font-style: normal;
text-decoration: none;
float: none;
}
.FormHeading
{
text-decoration: underline;
font-weight: bold;
position: relative;
left: 29px;
}
input[type=text]
{
width: 168px;
float: none;
}
input[type=text]:focus
{
float: none;
}
textarea
{
resize: none;
box-sizing: border-box;
position: relative;
top: -23px;
left: 01px;
width: 173px;
float: none;
}
input[type=submit]
{
background-color: #ADD8E6;
position: relative;
top: -44px;
left: 119px;
text-align: center;
}
请注意,我有HTC需求626,因此我正在设计移动网站。
答案 0 :(得分:0)
我正在与可能的解决方案共享一支笔:
您的职位是固定的,因此我使用百分比使其变得灵活。 让我知道是否可以。
form {
padding: 10px;
border-radius: 4px;
background: #d3d3d3;
width: 176px;
transform: translateX(-50%);
height: 319px;
position: absolute;
bottom: 0;
left: 50%;
font-family: "Arial", "Times New Roman", "Sans Serif";
font-style: normal;
text-decoration: none;
}
.FormHeading {
text-decoration: underline;
font-weight: bold;
position: relative;
left: 29px;
}
input[type="text"] {
width: 168px;
float: none;
}
input[type="text"]:focus {
float: none;
}
textarea {
resize: none;
box-sizing: border-box;
position: relative;
top: -23px;
left: 1px;
width: 173px;
float: none;
}
input[type="submit"] {
background-color: #add8e6;
position: relative;
top: -44px;
left: 119px;
text-align: center;
}
input[type=submit]
{
background-color: #ADD8E6;
position: relative;
top: -44px;
left: 119px;
text-align: center;
}
<form name="CommentsForm" action="Actionpage.php" onsubmit="return validateForm()" method="post">
<u class="FormHeading">Send Comment</u><br>
<br> First Name:<br>
<input type="text" name="firstname">
<br>
<div style="position: relative; top: 4px; left: 01px;">
Last Name:<br>
<input type="text" name="lastname">
</div>
<br>
<div style="position: relative; top: -13px; left: 1px;">
Email:<br>
<input type="text" name="email">
</div>
<br>
<div style="position: relative; top: -24px; left:03px;">
<label for="comment"> Comment:</label></div>
<textarea id="comment" name="comment" placeholder="Type commment here" style="height: 69px;"></textarea>
<br>
<br>
<input type="submit" name="submit" value="Send">
</form>
答案 1 :(得分:0)
像这样使用表单属性:
form { border: 10px solid #D3D3D3; border-radius: 4px; background: #D3D3D3; width: 176px; height: 319px; position: relative; margin: 0 auto; font-family: "Arial", "Times New Roman", "Sans Serif"; font-style: normal; text-decoration: none; }
我删除了您的浮动货币,并设置了相对位置并增加了保证金:0自动; 我猜您正在尝试将表单保留在屏幕中间?如果是,那么这将起作用。