我在尝试将导航栏居中放置在网页上时遇到问题。我尝试创建一个包装器div来居中,但似乎不起作用。在这个div中唯一有效的就是更改左边距。这是HTML:
body {
background: #bf5c71 url('body-bg.jpg');
}
.clearfix:after {
display: inline-block;
clear: both;
align-content: center;
}
/*----- Menu Outline -----*/
.menu-wrap {
box-shadow: inset 0px 0 0 rgba(255, 255, 255, 0.00);
-webkit-box-shadow: inset 0px 0 0 rgba(255, 255, 255, 0.00);
display: inline-block;
margin: 0px auto;
}
.menu {
display: inline-block;
margin: auto;
}
.menu li {
margin-top: 0px;
margin-right: 0px;
margin-left: 0px;
margin-bottom: 0px;
list-style: none;
font-family: 'Century Gothic';
}
.menu a {
transition: all linear 0.15s;
color: #FF283B;
}
.menu li:hover > a,
.menu .current-item > a {
color: #F5F5F5;
}
.menu .arrow {
font-size: 11px;
line-height: 0%;
}
/*----- Top Level -----*/
.menu > ul > li {
float: left;
display: inline-block;
position: relative;
font-size: 18px;
}
.menu > ul > li > a {
padding-top: 2px;
padding-right: 2px;
padding-left: 2px;
padding-bottom: 2px;
display: inline-block;
text-shadow: 0px 0px 0px rgba(0, 0, 0, 0.00);
}
.menu > ul > li:hover > a,
.menu > ul > .current-item > a {
background: F5F5F5;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index: 1;
opacity: 1;
}
.sub-menu {
width: 100%;
padding: 3px 0px;
position: absolute;
top: 100%;
left: 0px;
z-index: -1;
opacity: 0;
transition: opacity linear 0.15s;
box-shadow: 0px 0px 0px rgba(0, 0, 0, 0.0);
background: 0;
}
.sub-menu li {
display: inline-block;
font-size: 16px;
}
.sub-menu li a {
padding-top: 10px;
padding-right: 20px;
padding-left: 20px;
padding-bottom: 5px;
display: inline-block;
}
.sub-menu li a:hover,
.sub-menu .current-item a {
background: #FF283B;
}
img {
border: thin solid #FF283B;
margin-left: 5%;
}
h3 {
margin-top: 3%;
font-size: 24px;
}
.wrapper {
display: inline-block;
margin: 0px auto;
}
<div class="wrapper">
<div class="menu-wrap">
<nav class="menu">
<ul class="clearfix">
<li>
<div align="center"><a href="index.html">Home</a></a>
</div>
</li>
<li>
<div align="center"><a href="#">Projects <span class="arrow">▼</span></a>
<ul class="sub-menu">
<li><a href="iap.html">Image Adaptation</a>
</li>
<li><a href="sonic.html">Sonic Memory</a>
</li>
<li><a href="documentary.html">Documentary Video</a>
</li>
</ul>
</div>
</li>
<li>
<div align="center"><a href="resume.html">Resume</a>
</div>
</li>
<li>
<div align="center"><a href="about.html">About</a>
</div>
</li>
<li>
<div align="center"><a href="contact.html">Contact</a>
</div>
</li>
</ul>
</nav>
</div>
</div>
我唯一能做的就是使用左边距向左移动条形图。
网址:tylerbr.com
这就足够了:
.content {
text-align: center;
}
您需要给菜单一个宽度,并将显示更改为"block"
以下是您需要更改的样式
.menu-wrap {
box-shadow: 0 0 0 rgba(255, 255, 255, 0) inset;
display: block;
margin: auto;
width: 880px;
}
给导航条100%的宽度是个好主意。菜单上的文本居中对齐就可以了。
.menu-wrap {
box-shadow: inset 0px 0 0 rgba(255,255,255,0.00);
-webkit-box-shadow: inset 0px 0 0 rgba(255,255,255,0.00);
display: inline-block;
margin: 0px auto;
width: 100%;
}
.menu {
width: 100%;
display: inline-block;
text-align: center;
}
您想要的是他们的样式边距:0 auto;看看这个示例代码,你就会得到它。
<style>
.wrapper{
width:100%;
height: 30px;
background: black;
}
.centered_div{
width: 200px;
background: red;
margin:0 auto;
}
</style>
<div class="wrapper">
<div class="centered_div">
test
</div>
</div>