和标题一样,这是我的情况。 标题部分对我来说是好的,我设法将它居中,但菜单部分,我只是无法想象它。 这是HTML部分:
<div id="container">
<div id="topcontain">
<div id="header">
<div id="logo">
Logo Here
</div>
<div id="title">
<h1> THE TITLE HERE</h1>
</div>
</div>
</div>
<div id="menu">
<div id="menu_button">
<a href="#"> HOME </a>
</div>
<div id="menu_button">
<a href="#"> PRODUCTS </a>
</div>
<div id="menu_button">
<a href="#"> GALLERY </a>
</div>
<div id="menu_button">
<a href="#"> INFO </a>
</div>
<div id="menu_button">
<a href="#"> ABOUT US </a>
</div>
</div>
</div>
这是CSS部分:
@charset "utf-8";
html, body {
margin: 0px;
padding: 0px;
border: 0px;
font-family:Verdana, Geneva, sans-serif;
background-color:#000;
}
#container {
width: auto;
margin: 0 auto;
padding: 0;
}
#container #topcontain {
margin:20px 0px 20px 0px;
height:120px;
border-bottom:#F90 solid 3px;
}
#container #topcontain #header {
height:120px;
background:-moz-linear-gradient(#ffe2a3, #ffc341); /* FF3.6+ */
background:-webkit-linear-gradient(#ffe2a3, #ffc341); /* Chrome,Safari4+ */
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffffe2a3,endColorstr=#ffffc341); /* IE */
}
#container #topcontain #header #logo {
width:150px;
height:117px;
margin:auto;
float:left;
}
#container #topcontain #header #title {
width:auto;
position:relative;
margin: 0px 50px 0px 0px;
height:117px;
float:right;
color: #900;
font-size:20px;
font-family:Tahoma, Geneva, sans-serif;
}
#container #menu {
float:left;
width: 100%;
padding:0 auto;
background:#ffc341;
position:relative;
overflow:hidden;
}
#container #menu #menu_button{
margin:0;
width: 150px;
position:relative;
display:block;
text-decoration:none;
text-align:center;
background:#ffc341;
float:left;
font-size:18px;
color: #000;
border-right: #F90 thin solid;
}
#container #menu #menu_button a:link, #container #menu #menu_button a:visited{
text-decoration:none;
color:inherit;
}
#container #menu #menu_button:hover{
background-color: #F30;
color:#fff;
text-decoration: overline;
}
期待您的回复,谢谢。
答案 0 :(得分:0)
尝试将其删除:
float:left;
所以:
#container #menu {
background: none repeat scroll 0 0 #FFC341;
float: left;
overflow: hidden;
position: relative;
text-align: center;
width: 100%;
}
#container #menu #menu_button {
background: none repeat scroll 0 0 #FFC341;
border-right: thin solid #FF9900;
color: #000000;
display: inline-block;
float: left;
font-size: 18px;
margin: 0;
position: relative;
text-align: center;
text-decoration: none;
width: 150px;
}
答案 1 :(得分:0)
您可以尝试修改css部分中的container menu
#container #menu
{
margin:auto;
width:85%;
padding:0 auto;
background:#ffc341;
position:relative;
overflow:hidden;
}
试试这个,并在此处评论任何问题..
答案 2 :(得分:0)
这里用中心菜单
更正了html + css <html>
<head>
<style>
@charset "utf-8";
html, body {
margin: 0px;
padding: 0px;
border: 0px;
font-family:Verdana, Geneva, sans-serif;
background-color:#000;
}
#container {
width: auto;
margin: 0 auto;
padding: 0;
}
#container #topcontain {
margin:20px 0px 20px 0px;
height:120px;
border-bottom:#F90 solid 3px;
}
#container #topcontain #header {
height:120px;
background:-moz-linear-gradient(#ffe2a3, #ffc341); /* FF3.6+ */
background:-webkit-linear-gradient(#ffe2a3, #ffc341); /* Chrome,Safari4+ */
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffffe2a3,endColorstr=#ffffc341); /* IE */
}
#container #topcontain #header #logo {
width:150px;
height:117px;
margin:auto;
float:left;
}
#container #topcontain #header #title {
width:auto;
position:relative;
margin: 0px 50px 0px 0px;
height:117px;
float:right;
color: #900;
font-size:20px;
font-family:Tahoma, Geneva, sans-serif;
}
#container #menu {
width: 100%;
padding:0 auto;
background:#ffc341;
position:relative;
overflow:hidden;
}
#container #menu li{
margin:0;
width: 150px;
position:relative;
display:block;
text-decoration:none;
text-align:center;
background:#ffc341;
float:left;
font-size:18px;
color: #000;
border-right: #F90 thin solid;
}
#container #menu li a:link, #container #menu li a:visited{
text-decoration:none;
color:inherit;
}
#container #menu li:hover{
background-color: #F30;
color:#fff;
text-decoration: overline;
}
/*centered menu */
nav ul{
margin: 10px auto;
width: 755px;
}
</style>
</head>
<body
<div id="container">
<div id="topcontain">
<div id="header">
<div id="logo">
Logo Here
</div>
<div id="title">
<h1> THE TITLE HERE</h1>
</div>
</div>
</div>
<nav id="menu">
<ul>
<li>
<a href="#"> HOME </a>
</li>
<li>
<a href="#"> PRODUCTS </a>
</li>
<li>
<a href="#"> GALLERY </a>
</li>
<li>
<a href="#"> INFO </a>
</li>
<li>
<a href="#"> ABOUT US </a>
</li>
</ul>
</nav>
</div>
</body>
</html>
获得定心,给出ul的特定宽度(它也可能是div或其他)并给它一个左右的“自动”边距。
答案 3 :(得分:0)
由于#menu
的宽度设置为100%
,因此它会占用父元素的整个宽度,即#container
,width
为auto
},即窗口的宽度。
因此,您需要设置#menu
的宽度并将其与中心对齐,方法是删除浮动并进行以下更改:
#container #menu {
width: 755px; /* 151px x 5 elements */
margin:0 auto; /* Instead of padding */
position:relative;
overflow:hidden;
}
对于黄色背景,只需使用#menu
div包裹#menuWrapper
,并且在指定Italy时,id
在页面上应该是唯一的。请改用class
。
HTML:
<div id="menuWrapper">
<div id="menu">
<div class="menu_button">
<a href="#"> HOME </a>
</div>
<div class="menu_button">
<a href="#"> PRODUCTS </a>
</div>
<div class="menu_button">
<a href="#"> GALLERY </a>
</div>
<div class="menu_button">
<a href="#"> INFO </a>
</div>
<div class="menu_button">
<a href="#"> ABOUT US </a>
</div>
</div>
</div>
CSS:
#menuWrapper {
background:#ffc341;
}
此外,最好将ul-li
元素用于菜单项而不是div
完整的HTML + CSS:JSFiddle