我尝试将显示类型更改为内联块,将文本对齐更改为居中,并将位置更改为相对位置,但我尝试过的任何内容似乎都无法正常工作。
HTML代码:
<div id="header">
<h1>Politics and Social Media</h1>
<div id="navbar">
<ul id="menu">
<li><a href="index.html" class="button selected">Overview</a>
</li>
<li><a href="media.html" class="button">Media</a></li>
<li><a href="author.html" class="button">Author</a></li>
</ul>
</div>
<img src="images/barack.jpg" width="100%" height="75%" margin="0"
padding="0" alt="Barack Obama and Joe Biden looking at phone" >
</div><!--end of header-->
CSS代码:
#navbar {
width: 100%;
height: 45px;
overflow: hidden;
margin: 0;
}
ul#menu {
list-style: none;
margin-left: 0;
}
ul#menu li {
float: left;
margin-left: -40px;
}
答案 0 :(得分:0)
试试这个:
ul#menu {
list-style: none;
margin: 0 auto;
}
答案 1 :(得分:0)
这是你想要达到的目标吗?
CSS:
#header {
text-align: center;
}
#navbar {
width: 100%;
height: 45px;
overflow: hidden;
margin: 0;
}
ul#menu {
list-style: none;
padding-left: 0px;
}
ul#menu li {
display: inline-block;
}
HTML:
<div id="header">
<h1>Politics and Social Media</h1>
<div id="navbar">
<ul id="menu">
<li><a href="index.html" class="button selected">Overview</a>
</li>
<li><a href="media.html" class="button">Media</a></li>
<li><a href="author.html" class="button">Author</a></li>
</ul>
</div>
<img src="images/barack.jpg" width="100" height="75" margin="0"
padding="0" alt="Barack Obama and Joe Biden looking at phone" >
</div><!--end of header-->
答案 2 :(得分:0)
更改你的css,这样你就有了父母&gt; text-align:center and child&gt;显示:内联块;
ul#menu {
list-style: none;
margin-left: 0;
text-align:center;
padding:0px;
}
ul#menu li {
display:inline-block;
}
这里是JSFiddle