在同一导航栏上制作徽标和列表菜单

时间:2017-05-21 02:09:29

标签: html css

我想在同一导航栏上制作我的徽标和导航列表。起初,在我放置徽标之前,导航列表在内联工作良好 - 但是在我放置徽标后,它开始创建一个新行(导航列表)。

如果你们都能帮助我,我会很高兴的。您可以在codepen here

上查看我的代码

或者我会在这里发布。谢谢。我非常感谢你的帮助。

body{
  margin: 0;
  font-family: arial;
}

#background-img{
  width: 100%;
  border: 1px solid black;
  height: 198px;
  background: url('http://auxanograhicdesigns.com/media/wysiwyg/auxano/digital-marketing-services/web-designing-services/photoshop-banner-template-beautifull-web-banner-designs.jpg')
}

#nav-bar{
  top: 0;
  position:absolute;
  width: 100%;
  height: 63px;
  background-color: rgba(42, 34, 41, 0.6);
}
.logo{
  width: 86px;
  height:63px;;
  background-color: purple;
  margin-left: 30px;
  float:left;
  display: inline-block;
  color: white;
}

.logo p{
  text-align:center;
  padding-bottom: px;
  font-size: 30px;
}
#nav-bar ul{
  list-style-type: none;
  float: right;
}

#nav-bar li{
  display: inline-block;
  padding: 1%;
}

#nav-bar a {
  text-decoration: none;
  color: white;
  
}
<body>
  <div id = "wrapper">
    <div id = "background-img">
      <div id = "nav-bar">
        <a class = "logo" href = "#"><p>Ps</p></a>
       <nav>       
        <ul>
          <li><a href = "#">Home</a></li>
          <li><a href = "#">About</a></li>
          <li><a href = "#">Portofolio</a></li>
          <li><a href = "#">Contact</a></li>
        </ul>
      </nav>
      </div>
    </div>
  </div>
</body>

1 个答案:

答案 0 :(得分:1)

根据需要调整nav ul的宽度。你的错误是使用浮动(非常烦人,很难依赖它),并添加一个div作为导航容器:糟糕的搜索引擎优化和无用的内容,更多的代码到HTML。查看CodePen

<body>
  <div id = "wrapper">
    <div id = "background-img">
       <nav>
         <a class = "logo" href = "#"><p>Ps</p></a>
        <ul>
          <li><a href = "#">Home</a></li>
          <li><a href = "#">About</a></li>
          <li><a href = "#">Portofolio</a></li>
          <li><a href = "#">Contact</a></li>
        </ul>
      </nav>
    </div>
  </div>
</body>
 <!-- https://media.licdn.com/mpr/mpr/AAEAAQAAAAAAAANSAAAAJGRhYzRlMjllLTNlZTMtNDA1OS1iN2M2LTQ5NDI4YmFjZjJhOA.png --!>

body{
  margin: 0;
  font-family: arial;
}

#background-img{
  width: 100%;
  border: 1px solid black;
  height: 198px;
  background: url('http://auxanograhicdesigns.com/media/wysiwyg/auxano/digital-marketing-services/web-designing-services/photoshop-banner-template-beautifull-web-banner-designs.jpg')
}

nav{
  top: 0;
  position:absolute;
  width: 100%;
  height: 63px;
  background-color: rgba(42, 34, 41, 0.6);
}
.logo{
  width: 86px;
  height:63px;;
  background-color: purple;
  margin-left: 30px;
  display: inline-block;
  color: white;
}

.logo p{
  text-align:center;
  padding-bottom: px;
  font-size: 30px;
}
nav ul{
  text-align: right;
  list-style-type: none;
  display: inline-block;
  width: 90%;
}

nav li{
  display: inline;
  padding: 1%;
}

nav a {
  text-decoration: none;
  color: white;

}