我正在尝试创建一个联系表单,但我对容器有问题,它出现在左侧但是我希望它居中,我不想使用绝对定位,有人可以帮我吗? / p>
#contactustitle {
width: 100vw;
height: 18vh;
display: table;
background: transparent;
z-index: 1;
}
#contactustitle>h1 {
color: #fff;
font-family: raleway-bold;
font-size: 35px;
text-align: center;
vertical-align: middle;
text-transform: uppercase;
display: table-cell;
}
.whitebg {
width: 100vw;
height: 82vh;
background: #fff;
}
#contactus {
width: 70vw;
height: 82vh;
display: table-cell;
vertical-align: middle;
background: #fff;
text-align: center;
margin: 0 auto;
}
.whitebg .container {
display: table-cell;
vertical-align: middle;
}
#contactus .contactinfo {
float: left;
vertical-align: middle;
display: table-cell;
max-width: 40vw;
}
#contactus .contactinfo>li {
list-style: none;
display: inline-block;
margin-top: 15px;
margin-bottom: 15px;
}
#contactus .contactinfo>li>i,
#contactus .contactinfo>li>h5,
#contactus .contactinfo>li>p {
float: left;
display: inline-block;
vertical-align: top;
font-size: 15px;
-webkit-margin-before: 0;
-webkit-margin-after: 0;
margin-right: 10px;
}
#contactus .contactinfo>li>i {
font-size: 20px;
}
#contactus .contactinfo>li>h5 {
text-transform: uppercase;
font-family: raleway-semibold;
}
#contactus .contactinfo>li>p {
font-family: raleway-light;
text-align: left;
float: right;
margin-left: 20px;
max-width: 15vw;
}
<div class="whitebg">
<div class="container">
<div id="contactus">
<div class="contactinfo">
<li>
<i class="fa fa-street-view"></i>
<h5>Address:</h5>
<p>Lorem ipsium.</p>
<br></br>
</li>
<li>
<i class="fa fa-bolt"></i>
<h5>phone:</h5>
<p>Lorem ipsium.</p>
<br></br>
</li>
<li>
<i class="fa fa-shield"></i>
<h5>email:</h5>
<p>Lorem ipsium.</p>
</li>
<li>
<i class="fa fa-shield"></i>
<h5>hours:</h5>
<p>Lorem ipsium.</p>
</li>
</div>
</div>
</div>
</div>
我希望ID为“contactus”的分区水平居中,我尝试使用margin:0 auto和text-align-center,但它仍保留在左侧。
答案 0 :(得分:2)
使用display:table-cell会覆盖标准块级元素所期望的行为。我从有问题的div及其父容器中删除了它。
#contactustitle {
width: 100vw;
height: 18vh;
display: table;
background: transparent;
z-index: 1;
}
#contactustitle>h1 {
color: #fff;
font-family: raleway-bold;
font-size: 35px;
text-align: center;
vertical-align: middle;
text-transform: uppercase;
display: table-cell;
}
.whitebg {
width: 100vw;
height: 82vh;
background: #fff;
}
#contactus {
width: 70vw;
height: 82vh;
/*display: table-cell;*/
vertical-align: middle;
background: #fff;
text-align: center;
margin: 0 auto;
}
.whitebg .container {
/*display: table-cell;*/
vertical-align: middle;
}
#contactus .contactinfo {
float: left;
vertical-align: middle;
display: table-cell;
max-width: 40vw;
}
#contactus .contactinfo>li {
list-style: none;
display: inline-block;
margin-top: 15px;
margin-bottom: 15px;
}
#contactus .contactinfo>li>i,
#contactus .contactinfo>li>h5,
#contactus .contactinfo>li>p {
float: left;
display: inline-block;
vertical-align: top;
font-size: 15px;
-webkit-margin-before: 0;
-webkit-margin-after: 0;
margin-right: 10px;
}
#contactus .contactinfo>li>i {
font-size: 20px;
}
#contactus .contactinfo>li>h5 {
text-transform: uppercase;
font-family: raleway-semibold;
}
#contactus .contactinfo>li>p {
font-family: raleway-light;
text-align: left;
float: right;
margin-left: 20px;
max-width: 15vw;
}
<div class="whitebg">
<div class="container">
<div id="contactus">
<div class="contactinfo">
<li>
<i class="fa fa-street-view"></i>
<h5>Address:</h5>
<p>Lorem ipsium.</p>
<br></br>
</li>
<li>
<i class="fa fa-bolt"></i>
<h5>phone:</h5>
<p>Lorem ipsium.</p>
<br></br>
</li>
<li>
<i class="fa fa-shield"></i>
<h5>email:</h5>
<p>Lorem ipsium.</p>
</li>
<li>
<i class="fa fa-shield"></i>
<h5>hours:</h5>
<p>Lorem ipsium.</p>
</li>
</div>
</div>
</div>
</div>