我尝试了一切.我无法将这个集中在屏幕上.我正在使用ie 9但它在chrome中也是如此.它只是位于网页的左侧.感谢您的任何帮助.
<style type="text/css">
body {
margin:50px 0px; padding:0px;
text-align:center;
align:center;
}
label,input {
display: block;
width: 150px;
float: left;
margin-bottom: 10px;
}
label {
text-align: right;
width: 75px;
padding-right: 20px;
}
br {
clear: left;
}
</style>
</head>
<body>
<form name="Form1" action="mypage.asp" method="get">
<label for="name">Name</label>
<input id="name" name="name"><br>
<label for="address">Address</label>
<input id="address" name="address"><br>
<label for="city">City</label>
<input id="city" name="city"><br>
<input type="submit" name="submit" id="submit" value="submit" class="button" />
</form>
</body>
Run Code Online (Sandbox Code Playgroud)
Ale*_*ich 57
其他方式
body {
text-align: center;
}
form {
display: inline-block;
}Run Code Online (Sandbox Code Playgroud)
<body>
<form>
<input type="text" value="abc">
</form>
</body>Run Code Online (Sandbox Code Playgroud)
orf*_*orf 20
HTML:
<div class="form">
<form name="Form1" action="mypage.asp" method="get">
...
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
div.form
{
display: block;
text-align: center;
}
form
{
display: inline-block;
margin-left: auto;
margin-right: auto;
text-align: left;
}
Run Code Online (Sandbox Code Playgroud)
Cor*_*son 18
body { text-align: center; }
/* center all items within body, this property is inherited */
body > * { text-align: left; }
/* left-align the CONTENTS all items within body, additionally
you can add this text-align: left property to all elements
manually */
form { display: inline-block; }
/* reduces the width of the form to only what is necessary */
Run Code Online (Sandbox Code Playgroud)
在Chrome/IE/FF中运行和测试
tmj*_*jam 11
你可以试试
form {
margin-left: 25%;
margin-right:25%;
width: 50%;
}
Run Code Online (Sandbox Code Playgroud)
要么
form {
margin-left: 15%;
margin-right:15%;
width: 70%;
}
Run Code Online (Sandbox Code Playgroud)
尝试将此添加到您的CSS
.form { width:985px; margin:0 auto }
Run Code Online (Sandbox Code Playgroud)
并为body标签添加宽度:100%
然后把:
<div class="form">
Run Code Online (Sandbox Code Playgroud)
在标签之前.