2017-03-03 115 views
0

来源,我在网站项目劈砍而去,并正在努力获得引导下拉图标从自定义CSS显示当屏幕宽度足够小。我确定这是愚蠢的简单,但似乎无法弄清楚。引导 - 定制汉堡菜单,图像图标在CSS

最终看起来像一个复选框:

enter image description here

HTML:

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <title>Website Name</title> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
    <link href="css/style.css" rel="stylesheet" type="text/css" media="all" /> 
    <!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> --> 
</head> 
<body> 

<nav class="navbar navbar-inverse"> 
    <div class="container-fluid"> 
    <div class="navbar-header"> 
     <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar"> 
     <a href="#" id="test-icon"> 
     </button> 
     <a class="navbar-brand" href="index.html"><img alt="logo" src="images/db_logo_clean_60.png"</a> 
    </div> 
    <div class="collapse navbar-collapse" id="myNavbar"> 
     <ul class="nav navbar-nav navbar-right"> 
     <li><a href="#">ABOUT</a></li> 
     <li><a href="#">BLOG</a></li> 
     <li><a href="#">CONTACT</a></li> 
     </ul> 
    </div> 
    </div> 
</nav> 

<div class="container"> 
</div> 

</body> 
</html> 

CSS:

#test-icon { 

    display: hidden; 
    width: 40px; 
    height: 40px; 
    background: #515151 url(../images/menu-icon.png) center; 


} 
+0

'显示:hidden'心不是一个东西,也如果一个'了'元素,你需要给它'显示:block'或'显示:内联block'给它的高度和宽度等参数。它确实出现,但'a'甚至不会显示在'navbar-toggle'内部。也许,跳过中间人,并将'background'应用于'navbar-toggle'? – haxxxton

回答

0

简单的CSS解决方案

.navbar-header button.navbar-toggle { 
    display: none; 
} 

如果可以访问HTML所以删除按钮

<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar"><a href="#" id="test-icon"></a></button> 
0

只是修改根据自己的标准引导导航栏css--检查CSS我improvised--

的方式工作示例

.navbar-inverse .navbar-toggle .test-icon { 
 
    background-color: #fff; 
 
    background: url(https://cdn0.iconfinder.com/data/icons/ui-icons-pack/100/ui-icon-pack-01-512.png) center; 
 
} 
 
.navbar-toggle .test-icon { 
 
    display: block; 
 
    width: 22px; 
 
    height: 2px; 
 
    border-radius: 1px; 
 
}
<!doctype html> 
 
<html> 
 
<head> 
 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
 
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> 
 
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
 
      <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 
 
     
 
     <style type="text/css"> 
 
     
 

 

 
     </style> 
 
     <script type="text/javascript"> 
 
     
 
     </script> 
 
     </head> 
 
     
 
<body> 
 

 
<nav class="navbar navbar-inverse"> 
 
    <div class="container-fluid"> 
 
    <div class="navbar-header"> 
 
     <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar"> 
 
     
 
     <a href="#" class="test-icon"></a> 
 
     <!--<span class="test-icon"></span> 
 
     <span class="test-icon"></span>--> 
 
     </button> 
 
     <a class="navbar-brand" href="index.html"><img alt="logo" src="images/db_logo_clean_60.png"</a> 
 
    </div> 
 
    <div class="collapse navbar-collapse" id="myNavbar"> 
 
     <ul class="nav navbar-nav navbar-right"> 
 
     <li><a href="#">ABOUT</a></li> 
 
     <li><a href="#">BLOG</a></li> 
 
     <li><a href="#">CONTACT</a></li> 
 
     </ul> 
 
    </div> 
 
    </div> 
 
</nav> 
 

 
<div class="container"> 
 
</div> 
 

 
</body> 
 
</html> 
 
</body> 
 
</html>

注意:我从互联网上选择了自己的汉堡包图片,只需将它替换为你的。

希望这会有所帮助!