0

我是一名网页设计师爱好者,在我目前正在从事的项目中遇到了一些编码问题。我的目标是从这个网页重现菜单样式:http: //blueowlcreative.com/wp/aqua/。我希望它是全宽和居中的。这是我到目前为止所做的:

这是html:

<!-- Menu -->
<div id="menu">

<ul id="menu-bar">
    <li><a href="#">Home</a></li>

    <li><a href="#">Empresa</a>
        <ul>
            <li><a href="#">Nossa história</a></li>
            <li><a href="#">Sustentabilidade</a></li>
            <li><a href="#">Compromisso social</a></li>
        </ul>
    </li>

    <li><a href="#">Produtos</a></li>
    <li><a href="#">Cotação</a></li>

    <li><a href="#">Qualidade</a>
        <ul>
            <li><a href="#">Política da qualidade</a></li>
            <li><a href="#">Certificados</a></li>
        </ul>
    </li>

    <li><a href="#">Parceiros</a>
        <ul>
            <li><a href="#">Clientes</a></li>
            <li><a href="#">Fornecedores</a></li>
        </ul>
    </li>

    <li><a href="#">Contato</a></li>

</div><!-- end menu -->

这是CSS:

#menu {
  width: 100%;
  margin: 0;
  padding: 0;
  height: 60px;
  line-height: 100%;

  background: #494949;
  background: linear-gradient(top,  #494949,  #353535);
  background: -ms-linear-gradient(top,  #494949,  #353535);
  background: -webkit-gradient(linear, left top, left bottom, from(#494949), to(#353535));
  background: -moz-linear-gradient(top,  #494949,  #353535);
  border: solid 0px #6d6d6d;
  position:relative;
  z-index:999; }

#menu-bar {
  width: 937px;
  margin: 0 auto;
  height: 60px;
  line-height: 100%; }

#menu-bar li {
  margin: 0;
  padding: 0;
  float: left;
  position: relative;
  list-style: none; }

#menu-bar a {
  margin: 0;
  padding: 0px 20px 0px 20px;
  font-family: Open Sans;  
  font-weight: normal;
  font-size: 14px;
  color: #fff;
  text-decoration: none;
  display: block;
  line-height: 60px;
  text-shadow: 1px 1px 0px #000000; }

#menu-bar li ul li a {
  margin: 0;
  line-height: 20px; }

#menu-bar li:hover > a {
  background: #555757;
  color: #fff;

  -webkit-transition: all 0.2s linear;
  -moz-transition: all 0.2s linear;
  -ms-transition: all 0.2s linear;
  -o-transition: all 0.2s linear;
  transition: all 0.2s linear; }

#menu-bar ul a:hover {
  background: #0399d4;
  color: #fff;
  text-shadow: 1px 1px 0px #000; }

#menu-bar ul {
  display: none;
  margin: 0;
  padding: 0;
  width: 185px;
  position: absolute;
  top: 60px;
  left: 0;

  background: #4f5152;
  background-image: -moz-linear-gradient(#58595a,#414344);
  background-image: -o-linear-gradient(#58595a,#414344);
  background-image: -webkit-linear-gradient(#58595a,#414344);
  background-image: linear-gradient(#58595a,#414344);
  border: 1px solid #212223;
  border-top: 1px solid #212223;

  -moz-border-radius: 0px 0px 4px 4px;
  -webkit-border-radius: 0px 0px 4px 4px;
  -khtml-border-radius: 0px 0px 4px 4px;
  border-radius: 0 0 4px 4px;
  box-shadow: inset 0 3px 0 #45494b; }

#menu-bar li:hover > ul {
  display: block; }

#menu-bar ul li {
  float: none;
  margin: 0;
  padding: 0; }

#menu-bar ul a {
  padding: 15px 0px 15px 15px;
  color:#fff;
  text-shadow: 1px 1px 0px #000000; }

#menu-bar ul li:last-child > a {
  border-bottom-left-radius: 4px;
  -webkit-border-bottom-left-radius: 4px;
  -moz-border-radius-bottomleft: 4px;
  border-bottom-right-radius: 4px;
  -webkit-border-bottom-right-radius: 4px;
  -moz-border-radius-bottomright: 4px; }

#menu-bar:after {
  content: ".";
  display: block;
  clear: both;
  visibility: hidden;
  line-height: 0;
  height: 0; }

#menu-bar {
  display: inline-block; }

html[xmlns] #menu-bar {
  display: block; }

* html #menu-bar {
  height: 1%; }
4

1 回答 1

0

首先你应该关闭你的</ul>标签。

然后你应该在#menu 中添加一些样式。

top: 0;
left: 0;

改变你position:relative;position:fixed;

#menu {
  width: 100%;
  margin: 0;
  padding: 0;
  top: 0;
  left: 0;
  height: 60px;
  line-height: 100%;

  background: #494949;
  background: linear-gradient(top,  #494949,  #353535);
  background: -ms-linear-gradient(top,  #494949,  #353535);
  background: -webkit-gradient(linear, left top, left bottom, from(#494949), to(#353535));
  background: -moz-linear-gradient(top,  #494949,  #353535);
  border: solid 0px #6d6d6d;
  position:fixed;
  z-index:999; 
  }

添加float: right;你的#menu-bar

#menu-bar {
  width: 937px;
  margin: 0 auto;
  height: 60px;
  line-height: 100%;
  float: right;
  }
于 2013-12-04T06:39:04.497 回答