2017-04-25 195 views
0

我在嘗試弄清楚如何爲我的網站設置背景圖片時遇到問題,而不會影響我的導航欄。看起來像圖像喜歡爲我的導航欄顯示。這似乎是我的導航欄上有我的CSS問題?我對HTML/CSS相當新,所以任何幫助將不勝感激:)。顯示在NavBar下的背景圖片

Image Problem

html { 
 
    background: url(background-image.png) no-repeat center center fixed; 
 
    -webkit-background-size: cover; 
 
    -moz-background-size: cover; 
 
    background-size: cover; 
 
} 
 

 
/* TOP-NAV CSS */ 
 

 
.navbar { 
 
    margin: 0 auto; 
 
    padding: 0; 
 
    font-family: 'Roboto', sans-serif; 
 
    font-weight: 400; 
 
    line-height: 1.43; 
 
    color: #484848; 
 
    overflow-x: hidden; 
 
} 
 

 
.top-nav { 
 
    position: relative; 
 
    width: 100%; 
 
    height: auto; 
 
    border-bottom: 1px solid #ccc; 
 
} 
 

 
.logo:link { 
 
    position: relative; 
 
    color: #484848; 
 
    display: inline-block; 
 
    transition: all 0.3s ease; 
 
    -webkit-transition: all 0.3s ease; /*Chrome/Opera/Safari */ 
 
    -moz-transition: all 0.3s ease; /* Firefox */ 
 
    -ms-transition: all 0.3s ease; /* IE */ 
 
} 
 

 
.logo:visited { 
 
    color: #484848; 
 
} 
 

 
.logo:hover { 
 
    background-color: #f1f1f1; 
 
} 
 

 
/* Image Logo */ 
 

 
.logo img { 
 
    position: relative; 
 
    padding: 16px 19px; 
 
    width: 100px; 
 
    border-right: 1px solid #ccc; 
 
    vertical-align: middle; 
 
} 
 

 
/* NAV-SEARCH CSS */ 
 

 
#nav-search-wrapper { 
 
    display: inline-block; 
 
    width: 490px; 
 
    height: 100%; 
 
} 
 

 
/* Search Bar Form */ 
 

 
#nav-search-wrapper form input { 
 
    padding: 18px 10px 18px 52px; 
 
    width: 100%; 
 
    border: none; 
 
    outline: none; 
 
    color: #666; 
 
    font-size: 14px; 
 
    box-sizing: border-box; 
 
    -webkit-box-sizing: border-box; 
 
    -moz-box-sizing: border-box; 
 
    background-image: url('search-icon.svg'); 
 
    background-repeat: no-repeat; 
 
    background-position: 25px; 
 
    background-size: 18px; 
 
}
<div class="navbar navbar-default navbar-fixed-top"> 
 
    <header> 
 
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalabe=no" /> 
 
    <link rel="stylesheet" type="text/css" href="header.css" /> 
 
    <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,700" rel="stylesheet" /> 
 
     <div class="top-nav clearfix"> 
 
     <a href="" class="logo"> 
 
     <img src="" class="logo"/> 
 
     </a> 
 
     <div id="nav-search-wrapper"> 
 
      <form method="GET" action=""> 
 
      <input type="text" name="search" id="nav-search" placeholder="Search" /> 
 
      </form> 
 
     </div> 
 
     <ul> 
 
     <li><a href="">Ticket Form</a></li> 
 
     <li><a href="">Locations</a></li> 
 
     <li><a href="">About Us</a></li> 
 
     <li><a href="">Sign Up</a></li> 
 
     </ul> 
 
     </div> 
 
    </header> 
 
</div>

+1

看看你的'.navbar'類。它只是沒有背景屬性 – DestinatioN

+1

也許嘗試爲你的'.navbar'類設置一個'background-color:white'? – melvindidit

+0

我嘗試將背景色設置爲某種顏色,但它仍然有圖像與我的導航欄重疊。 – archeryninja

回答

0

如果你想文本字段變得透明。和您的網站的背景圖片,而不會干擾該導航欄。

然後

在.css文件添加透明度。

像這樣

#nav-search-wrapper { display: inline-block; width: 490px; height: 100%; opacity: 0.6; filter: alpha(opacity=60); } 
+0

我想讓我的整個導航欄的背景顏色爲白色。搜索欄是正確的顏色,但其餘部分是重疊的。 – archeryninja

0

嘗試把你的.navbar background-color: #fffz-index財產,看看它是否重疊,你的背景。

檢查此更新的答案。所有在這裏工作得很好,或者你最好發佈你的所有代碼,以便我們能夠弄清楚它的真正問題是什麼。

body { 
 
    // background: url(background-image.png) no-repeat center center fixed; 
 
     -webkit-background-size: cover; 
 
     -moz-background-size: cover; 
 
     background-size: cover; 
 
     background-color: #000; /* just to check if the background applies */ 
 
    } 
 
    
 
    /* TOP-NAV CSS */ 
 
    .navbar { 
 
     margin: 0 auto; 
 
     padding: 0; 
 
     font-family: 'Roboto', sans-serif; 
 
     font-weight: 400; 
 
     line-height: 1.43; 
 
     color: #484848; 
 
     overflow-x: hidden; 
 
     background-color: #fff; /* whole top bar will filled by white color */ 
 
    } 
 

 
    .top-nav { 
 
     position: relative; 
 
     width: 100%; 
 
     height: auto; 
 
     border-bottom: 1px solid #ccc; 
 
    } 
 

 
    .logo:link { 
 
     position: relative; 
 
     color: #484848; 
 
     display: inline-block; 
 
     transition: all 0.3s ease; 
 
     -webkit-transition: all 0.3s ease; 
 
     /*Chrome/Opera/Safari */ 
 
     -moz-transition: all 0.3s ease; 
 
     /* Firefox */ 
 
     -ms-transition: all 0.3s ease; 
 
     /* IE */ 
 
    } 
 

 
    .logo:visited { 
 
     color: #484848; 
 
    } 
 

 
    .logo:hover { 
 
     background-color: #f1f1f1; 
 
    } 
 
    /* Image Logo */ 
 

 
    .logo img { 
 
     position: relative; 
 
     padding: 16px 19px; 
 
     width: 100px; 
 
     border-right: 1px solid #ccc; 
 
     vertical-align: middle; 
 
    } 
 
    /* NAV-SEARCH CSS */ 
 

 
    #nav-search-wrapper { 
 
     display: inline-block; 
 
     width: 490px; 
 
     height: 100%; 
 
    } 
 
    /* Search Bar Form */ 
 

 
    #nav-search-wrapper form input { 
 
     padding: 18px 10px 18px 52px; 
 
     width: 100%; 
 
     border: none; 
 
     outline: none; 
 
     color: #666; 
 
     font-size: 14px; 
 
     box-sizing: border-box; 
 
     -webkit-box-sizing: border-box; 
 
     -moz-box-sizing: border-box; 
 
     background-image: url('search-icon.svg'); 
 
     background-repeat: no-repeat; 
 
     background-position: 25px; 
 
     background-size: 18px; 
 
    }
<div class="navbar navbar-default navbar-fixed-top"> 
 
    <header> 
 
     <div class="top-nav clearfix"> 
 
      <a href="" class="logo"> 
 
       <img src="" class="logo" /> 
 
      </a> 
 
      <div id="nav-search-wrapper"> 
 
       <form method="GET" action=""> 
 
        <input type="text" name="search" id="nav-search" placeholder="Search" /> 
 
       </form> 
 
      </div> 
 
      <ul> 
 
       <li><a href="">Ticket Form</a></li> 
 
       <li><a href="">Locations</a></li> 
 
       <li><a href="">About Us</a></li> 
 
       <li><a href="">Sign Up</a></li> 
 
      </ul> 
 
     </div> 
 
    </header> 
 
</div>

+0

這對我不起作用:( – archeryninja

+0

@archeryninja - 我更新了我的答案。請參閱我將'html'替換爲'body',並且還將整個身體設置爲整個導航的黑白背景。除非你用你的所有代碼更新了你的帖子 – Grinex

+0

我能夠解決這個問題,我不得不用背景設置top-nav,謝謝你, – archeryninja