gpt4 book ai didi

html - 文本对齐 :center not working even after setting display:block

转载 作者:太空宇宙 更新时间:2023-11-04 14:59:12 31 4
gpt4 key购买 nike

我正在尝试使表单内容居中。但是即使在为表单容器设置了 display:block 然后应用 text-align:center 之后它也不起作用;我做了另一项工作 put padding:0 33% 它将居中表单内容,但具有不同的视口(viewport)大小,它会缩小文本框的大小。我想将表单元素居中并希望它们占据容器大小,请解释为什么会发生这种情况以及我忽略了什么。我希望它能够适用于所有视口(viewport)大小。我想知道导致这种情况甚至覆盖内联代码的原因

Demo

CSS

 #Banner{
background:url('http://i67.tinypic.com/midkki.png') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
width:100%;
min-height:960px;


}
#Menu{
min-height:120px;

}
body,html{
padding:0;
margin:0;
}
.nopm{
padding:0;
margin:0;
}
#Menu ul{
padding:0;
margin:0;



}
#Menu li{
list-style:none;
float:left;
padding:1em .3em;
float:left;
margin:2em 0;

}
#Menu a{

text-decoration:none;
font-family: Rockwell,Courier Bold,Courier,Georgia,Times,Times New Roman,serif;
font-size: 24px;
font-style: normal;
font-variant: normal;
font-weight: 600;
line-height: 28px;
color:#fff;
margin:1em .5em;
padding:10px;
border:2px solid #fff;

}
a:hover{

border:4px solid #FFD700;
-webkit-transition-delay: 2s; /* Safari */
transition-delay: 2s;
}
@media (max-width:420px){

li{

width:100%;
text-align:center;

}
img{
display:block;
width:90px;
height:90px;
margin:0 auto;
}
}
h1,h3{color:#fff;
text-align:center;

}
#Slogan
{
padding:2em 0;
}
#SignUpWrapper{
width:100%;
text-align: center;
display:block;
}
form{

width:100%;
}
input[type="text"],[type="email"],[type="password"]{
font-family: Rockwell,Courier Bold,Courier,Georgia,Times,Times New Roman,serif;
font-size: 19px;
font-style: normal;
font-variant: normal;
font-weight: 600;
line-height: 25px;
color:#000 !important;
padding:.5em;
width:100%;

}

HTML

<body>
<div id="Banner">
<div id="Menu">
<div class="row nopm">
<div class="col-lg-3 col-md-3 col-sm-2">
</div>
<div class="col-lg-1 col-md-1 col-sm-1">
<img src="http://i66.tinypic.com/xpon69.png" />
</div>
<div class="col-lg-3 col-md-1 col-sm-1">
</div>
<div class="col-lg-3 col-md-5 col-sm-7">
<ul>
<li>
<a href="#">Events</a>
</li>
<li>
<a href="#">Login</a>
</li>
</ul>
</div>
<div class="col-lg-2 col-md-2 col-sm-1">
</div>
</div>

</div>
<div id="Slogan">
<div class="row nopm">
<div class="col-lg-4 col-xs-12">
</div>
<div class="col-lg-4 col-xs-12">

<h1>
Welcome to Meet Up Place
</h1>
<h3>
SignUp to create your own events
</h3>
</div>
<div class="col-lg-4 col-xs-12">
</div>
</div>
</div>
<div id="SignUp">
<div class="row nopm">
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
</div>
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
<div id="SignUpWrapper">
<form autocomplete="on">
<div class="InputWrapper">
<div class="input-group">
<label for="fName" style=" display: block;text-align:center;">First Name</label>
</div>
<div class="input-group">
<input class="form-control" id="fName" type="text" placeholder="First Name" >
</div>
</div>
<div class="InputWrapper">
<div class="input-group">
<label for="lName">Last Name</label>
</div>
<div class="input-group">
<input id="lName" type="text" placeholder="Last Name" />
</div>
</div>
<div class="InputWrapper">
<div class="input-group">
<label for="lName">E-Mail</label>
</div>
<div class="input-group">
<input id="lName" type="email" placeholder="E-Mail" />
</div>
</div>


</form>
</div>

</div>
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12">
</div>
</div>
</div>
</div>
</body>

最佳答案

form 上放置 display: inline-block; 并删除 width: 100%; 并且它起作用了。

See it here

如果你想让内部内容居中,试试这个:

.input-group { display: block !important; }
.form-control, input[type="text"], [type="email"], [type="password"] { text-align : center !important;}

我使用 !important 因为样式在 HTML 面板而不是 CSS 面板中。

您的内联样式已应用:

enter image description here

关于html - 文本对齐 :center not working even after setting display:block,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36621081/

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