导航栏背景没有显示

时间:2014-12-10 10:21:23

标签: html css

我正在构建一个非常基本的导航栏,但我无法弄清楚为什么我的样式表中设置的导航栏的背景颜色(我相信我已正确设置)没有显示。

以下是我希望在后台实现的目标:

desired outcome

这就是我迄今取得的成就

current outcome

这是我的CSS代码:

    @import url(http://fonts.googleapis.com/css?family=Open+Sans:700);

html {height: 100%; width: 100%;}

body {
    height: 100%; 
    width: 100%;
    margin: 0; 
    padding: 0; 
    border: 0;
    font-family: "Helvetica", Arial, sans-serif;
    font-size: 14px; 
    line-height: 15px;
}

/* Top bar*/
.topbar {
  background: #F96E5B;
  height: 50px;
  width: auto;
}

/* Logo img button*/
#topbar img {
    position: absolute;
    float: left;
    width: 125px;
    height: 25px;
    padding-left: 12px;
    padding-top: 12px;
}

/* ul */
#topbar ul {
    float: right;
    list-style: none;
    margin: 0;
    padding: 0;
    line-height: 1;
    display: block;
    zoom: 1;
}

/* li */
#topbar ul li {
    display: inline-block;
    padding: 0;
    margin: 0;
}

/* Insert a gap after every <ul> element */
#topbar ul:after {
  content: " ";
  display: block;
  font-size: 0;
  height: 0;
  clear: both;
  visibility: hidden;
}

/* li */
#topbar ul li a {
  color: #000000;
  text-decoration: none;
  display: block;
  padding: 15px 25px;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 14px;
  position: relative;
  -webkit-transition: color .25s;
  -moz-transition: color .25s;
  -ms-transition: color .25s;
  -o-transition: color .25s;
  transition: color .25s;  
}

#topbar ul li a:hover {
  color: #FFCC00;
}

/* bullet point after the menu name */
#topbar ul li a:after {
  content: "";
  display: block;
  position: absolute;
  right: -3px;
  top: 19px;
  height: 6px;
  width: 6px;
  background: #FF0000;
  opacity: .5;
}

#topbar ul li a:before {
  content: "";
  display: block;
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 0;
  background: #00FF00;
  -webkit-transition: width .25s;
  -moz-transition: width .25s;
  -ms-transition: width .25s;
  -o-transition: width .25s;
  transition: width .25s;
}

#topbar ul li.last > a:after,
#topbar ul li:last-child > a:after {
  display: none;
}

#topbar ul li.active a {
  color: #FFDD00;
}

#topbar ul li.active a:before {
  width: 100%;
}

#topbar.align-right li.last > a:after,
#topbar.align-right li:last-child > a:after {
  display: block;
}
#topbar.align-right li:first-child a:after {
  display: none;
}

这是我的HTML代码:

    <!DOCTYPE html>
<html>

    <head>
       <meta charset='utf-8'>
       <meta http-equiv="X-UA-Compatible" content="IE=edge">
       <meta name="viewport" content="width=device-width, initial-scale=1">
       <link rel="stylesheet" href="stylesheets/public.css">
       <title>Welcome to Swim-mates</title>    
    </head>

<body>
    <div id="topbar">
        <img src="images/logoimg.png">
        <!-- <button class="login" type="submit">Log In</button> -->

        <ul>
           <li class='active'><a href='#'><span>Home</span></a></li>
           <li><a href='#'><span>Products</span></a></li>
           <li><a href='#'><span>Company</span></a></li>
           <li class='last'><a href='#'><span>Contact</span></a></li>
        </ul>       
    </div>

    <div class="main">

        <div id="welcome_message">

        </div>

        <div id="slideshow">

        </div>

        <div id="signup">

        </div>              

    </div>
</body>

</html>

我确信这对我来说是一个小小的疏忽。感谢您的任何建议。

2 个答案:

答案 0 :(得分:4)

您正在使用HTML中的ID,因此请使用“#”作为上边栏

试试这个

/* Top bar*/
#topbar {
  background: #F96E5B;
  height: 50px;
  width: auto;
}

答案 1 :(得分:2)

.topbar {
  background: #F96E5B;
  height: 50px;
  width: auto;
}

需要

#topbar {
  background: #F96E5B;
  height: 50px;
  width: auto;
}

因为你声明了&#34; topbar&#34;作为id