我一直在这个网站上寻找解决此问题的答案,但没有一个有效或者我已经在我的代码中使用了给出的答案。以下是我的代码:
@import url(http://fonts.googleapis.com/css?family=Roboto:500,400italic,300,500italic,300italic,400);
@import url(http://fonts.googleapis.com/css?family=Quicksand:300,400,700);
html {
font-family: Roboto, sans-serif;
width: 100%;
height: 100%;
}
body {
margin: 0 0 0 0;
width: 100%;
height: 100%;
}
.the-big-image {
margin: 0 0 0 0;
width: 100%;
height: 100%;
background-image: url(img/rocks.jpg);
}
.the-big-image-cover {
margin: 0 0 0 0;
width: 100%;
height: 100%;
background: -webkit-linear-gradient(rgba(0, 77, 64, 0.28), rgba(0, 0, 0, 0.5));
/* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(rgba(0, 77, 64, 0.28), rgba(0, 0, 0, 0.5));
/* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(rgba(0, 77, 64, 0.28), rgba(0, 0, 0, 0.5));
/* For Firefox 3.6 to 15 */
background: linear-gradient(rgba(0, 77, 64, 0.28), rgba(0, 0, 0, 0.5));
/* Standard syntax */
}
nav {
margin: 0 0 0 0;
width: 100%;
height: 70px;
}
.nav-wrapper {
margin: 0 auto 0 auto;
width: 70%;
height: 100%
}
.brand-logo {
font-family: quicksand, sans-serif;
color: rgba(0, 0, 0, .7);
font-size: 40pt;
font-weight: 300;
display: inline-block;
margin: 0 auto 0 auto;
width: 300px;
}
.text-center {
text-align: center;
}
.divider {
width: 100%;
height: 1px;
background-color: rgba(0, 0, 0, 0.4);
box-shadow: 1px 1px 5px #888888;
}
.hamburger-container {
background-color: rgba(0, 0, 0, 0);
border: none;
dispaly: inline-block;
}
.icon-bar {
margin: 4px 4px 4px 4px;
display: block;
width: 45px;
height: 2px;
background-color: rgba(0, 0, 0, 0.4);
border-radius: 2px;
}
.right {
float: right;
}
<body>
<div class="the-big-image">
<div class="the-big-image-cover">
<nav>
<div class="nav-wrapper">
<span class="brand-logo text-center">logo</span>
<button class="hamburger-container right">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
</nav>
<div class="divider"></div>`
我想知道为什么类名为.brand-logo
的元素无法居中。我已经为它设置了宽度,确保它不是块级元素,并添加了margin
代码并将其设置为auto。为什么还是无法实现居中?