I am working on making a personal site by playing around with bootstrap and I have a transparent navigation bar that looks like this:
Written like this:
<nav class="navbar navbar-default navbar-fixed-top navbar-shrink">
<div class="container">
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#home">Jon Snow - Knows Nothing</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="page-scroll">
About Me
</li>
<li class="page-scroll">
Work
</li>
<li class="page-scroll">
Blog
</li>
<li class="page-scroll">
Contact Me
</ul>
</div>
</div>
</nav>
This how the CSS is setup with different profiles for desktop and mobile sites:
#media only screen
and (min-width: 768px) {
.navbar.navbar-default {
padding:6px;
background: rgba(0, 0, 0, 0);
border: none;
}
.navbar.navbar-default .navbar-nav > li > a,
.navbar.navbar-default .navbar-brand {
color: white;
}
.navbar.navbar-default .navbar-collapse {
border: none;
box-shadow: none;
}
}
#media only screen and (max-width: 767px) {
.navbar.navbar-default {
background: rgba(0, 0, 0, .5);
border: none;
}
.icon-bar {
background-color:#ffffff !important;
}
.navbar.navbar-default .navbar-nav > li > a,
.navbar.navbar-default .navbar-brand {
color: white;
}
.navbar.navbar-default .navbar-collapse {
border: none;
box-shadow: none;
}
I am trying to add a highlight on hover and focus to my navbar item that is supposed to look like this:
I tried variations of this but no luck:
.nav li > a {
background-color:#000000;
color: #ffffff;
}
Also here is fiddle: JSFiddle
This may work!
.navbar.navbar-default .navbar-nav li a:hover {
background-color:#000000;
color: #ffffff;
border-radius:5px;
}
Related
The fixed navbar was working but suddenly it stopped on Firefox. When I tried on other browsers (chrome, ie, opera) it works right now but not on FF. I tried to start FF in safe mode but no difference. What is wrong?
.nav-tabs li a {
color: #777;
}
.navbar {
margin-bottom: 0;
background-color: #153870;
border: 0;
font-size: 15px !important;
letter-spacing: 4px;
opacity:0.9;
}
.navbar li a, .navbar .navbar-brand {
color: #ffef03 !important;
}
.navbar-nav li a:hover {
color: #3AA83D !important;
}
.navbar-nav li.active a {
color: #fff !important;
background-color:#29292c !important;
}
.navbar-default .navbar-toggle {
border-color: transparent;
}
.open .dropdown-toggle {
color: #ffef03 ;
background-color: #153870 !important;
}
.dropdown-menu li a {
color: #ffef03 !important;
}
.dropdown-menu li a:hover {
background-color: #153870 !important;
}
<nav id="myNB" class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavb">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Obrakadabra!..</a>
</div>
<div class="collapse navbar-collapse" id="myNavb">
<ul class="nav navbar-nav navbar-right">
<li>Askerleri</li>
<li>Koç Hakkında</li>
<li>Ne dediler?</li>
<li>O ne dedi?</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Dahası
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>Mekanı</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
i want to change the color of my navbar when i scroll. When the navbar is on top the background is transparent.
thank's to all for the attention and excuse me for my bad english!!
/* COLORE NAVBAR */
.navbar-default .navbar-toggle .icon-bar {
background-color: #fff;
box-shadow: 1px 1px #000;
}
.navbar-toggle {
background-color: transparent;
border: none;
}
.navbar-toggle:hover {
background-color: transparent! important;
}
.navbar-toggle:focus {
background-color: transparent! important;
}
.navbar-default {
background-color: transparent;
border-color: transparent;
}
.navbar-default .navbar-nav>li>a {
color: #FFF;
text-shadow: 1px 1px #000;
}
.navbar-default .navbar-nav>li>a:focus,
.navbar-default .navbar-nav>li>a:hover {
color: red;
}
.navbar-default .navbar-nav>.active>a,
.navbar-default .navbar-nav>.active>a:focus,
.navbar-default .navbar-nav>.active>a:hover {
background-color: yellow;
}
.navbar-default .navbar-nav>.open>a,
.navbar-default .navbar-nav>.open>a:focus,
.navbar-default .navbar-nav>.open>a:hover {
background-color: blue;
}
.dropdown-menu>li>a {
color: green;
}
.dropdown-menu>li>a:hover {
background-color: brown;
color: violet;
}
.navbar-brand>li>a:hover {
color: white;
}
#media only screen and (max-width: 766px) {
.collapsing,
.in {
background: #fff;
}
.collapsing ul li a,
.in ul li a {
color: #fff!important;
float: left;
}
.collapsing ul li a:hover,
.in ul li a:hover {
color: #fff !important;
background-color: #E1332D;
}
}
<!-- Navigation -->
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand page-scroll" href="#page-top" style="color: white;">LUCA DELCONTE</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<!-- Hidden li included to remove active class from about link when scrolled up past about section -->
<li class="hidden">
<a class="page-scroll" href="#page-top"></a>
</li>
<li>
<a class="page-scroll" href="#about"><i class="fa fa-smile-o" aria-hidden="true"></i>
About</a>
</li>
<li>
<a class="page-scroll" href="#services"><i class="fa fa-diamond" aria-hidden="true"></i>
Design</a>
</li>
<li>
<a class="page-scroll" href="#work"><i class="fa fa-lightbulb-o" aria-hidden="true"></i>
Work</a>
</li>
<li>
<a class="page-scroll" href="#contact"><i class="fa fa-envelope" aria-hidden="true"></i>
Contact</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
Use the Bootstrap Affix component to watch the scroll position instead of extra jQuery/JavaScript. Just define the .affix-top and .affix CSS for the navbar.
/* navbar style once affixed to the page */
.affix {
background-color: black;
}
#media (min-width:768px) {
.affix-top {
/* navbar style at top */
background-color:transparent;
border-color:transparent;
padding: 15px;
}
}
and set the position you want the navbar to change style (ie; 400px from the top)
<div class="navbar navbar-inverse navbar-fixed-top" data-spy="affix" data-offset-top="400">
Working Demo:
http://www.codeply.com/go/xp2fY6sVHP
For Bootstrap 4, see: Animate/Shrink NavBar on scroll using Bootstrap 4
jQuery
/**
* Listen to scroll to change header opacity class
*/
function checkScroll(){
var startY = $('.navbar').height() * 2; //The point where the navbar changes in px
if($(window).scrollTop() > startY){
$('.navbar').addClass("scrolled");
}else{
$('.navbar').removeClass("scrolled");
}
}
if($('.navbar').length > 0){
$(window).on("scroll load resize", function(){
checkScroll();
});
}
I can't figure out what's wrong with my index.html or main.css. I'm using Bootstrap with a custom stylesheet to add a few new things to my layout.
Anyways, I made a one-page website and all the menu items are going to the right section but only 1 link is going to another website, this link isn't working. If I right click it and click on open in a new tab it is working. But just clicking the menu item isn't possible.
Here is my navigation HTML:
<header id="header" role="banner">
<div class="container">
<div id="navbar" class="navbar navbar-default">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html"></a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><i class="icon-home"></i>
</li>
<li>Services
</li>
<li>About Us
</li>
<li>Gallery
</li>
<li>Brands
</li>
<li>Hours
</li>
<li>Contact
</li>
<li>Store
</li>
</ul>
</div>
</div>
</div>
</header>
Here is my navigation CSS:
#header {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 80px;
z-index: 99999;
}
.navbar-default {
background: #fff;
border-radius: 0 0 5px 5px;
border: 0;
padding: 0;
-webkit-box-shadow: 0 1px 3px 0 rgba(0, 0, 0, .2);
-moz-box-shadow: 0 1px 3px 0 rgba(0, 0, 0, .2);
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, .2);
overflow: hidden;
}
.navbar-default .first a {
border-radius: 0 0 0 5px;
}
.navbar-default .navbar-brand {
margin-right: 50px;
margin-left: 20px;
width: 200px;
height: 78px;
background: url(../images/logo.png) no-repeat 0 50%;
}
.navbar-default .navbar-nav > li {
margin-left: 1px;
}
.navbar-default .navbar-nav > li > a {
padding: 30px 25px;
font-size: 16px;
line-height: 18px;
color: #999;
}
.navbar-default .navbar-nav > li > a > i {
display: inline-block;
}
.navbar-default .navbar-nav > li.active > a,
.navbar-default .navbar-nav > li.active:focus > a,
.navbar-default .navbar-nav > li.active:hover > a,
.navbar-default .navbar-nav > li:hover > a,
.navbar-default .navbar-nav > li:focus > a,
.navbar-default .navbar-nav > li.active > a:focus,
.navbar-default .navbar-nav > li.active:focus > a:focus,
.navbar-default .navbar-nav > li.active:hover > a:focus,
.navbar-default .navbar-nav > li:hover > a:focus,
.navbar-default .navbar-nav > li:focus > a:focus {
background-color: #f57e20;
color: #fff;
}
Here is a fiddle:
https://jsfiddle.net/jh6ufp75/3/
Is someone able to help me out with this problem?
Thanks a lot!
Kind regards.
There's a problem in the ul and li class of your template.
If you remove li tag it works fine, give it a try
<div>Store</div>
The problem is that you have to restyle your div tag for looking the same at the other menu elements.
I went further...
The root of the problem is in main.js at line 20:
//smooth scroll
$('.navbar-nav > li').click(function(event) {
event.preventDefault();
var target = $(this).find('>a').prop('hash');
$('html, body').animate({
scrollTop: $(target).offset().top
}, 500);
});
So... this script prevent li tag in your nav-bar from the default click action, and go to anchors in your html files.
Because you are linking to an external link, there's no "top" propriety for your menu item, and if you check your console log you get this error:
main.js:25 Uncaught TypeError: Cannot read property 'top' of undefined
You can simply use div tag instead of li and style it like a menu item.
Add target="_blank"; to your Store menu link. and it's working fine.
Code:
<header id="header" role="banner">
<div class="container">
<div id="navbar" class="navbar navbar-default">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html"></a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><i class="icon-home"></i></li>
<li>Services</li>
<li>About Us</li>
<li>Gallery</li>
<li>Brands</li>
<li>Hours</li>
<li>Contact</li>
<li>Store</li>
</ul>
</div>
</div>
</div>
</header>
I've made my navbar a clearfix and added another ul to the right side of it, now it doesn't work in mobile view mode on Chrome?
When using mobile view the drop down button no longer works, also at some view ports it displays the bar in two lists making the navbar a lot taller?
HTML
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Logo</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li>
Tyres
</li>
<li>
Mags
</li>
<li>
Gallery
</li>
<li>
Blog
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
Locate a Store
</li>
<li>
Cart
</li>
<li>
Search
</li>
<li>
Login
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
CSS Code Below
.navbar {
font-size: 14px;
font-weight: 300;
line-height: 1.6;
min-height: 65px;
position: fixed;
}
.navbar-inverse .navbar-brand {
color: #ffffff;
}
.navbar-inverse .navbar-nav>li>a {
color: #ffffff;
float: left;
line-height: 60px;
padding: 0 30px;
text-decoration: none;
}
/* Clearfix the Navbar */
.clearfix:before, .clearfix:after,
.navbar:before, .navbar:after {
content: " "; display: table;
}
.clearfix:after,
.navbar:after {
clear: both;
}
/* Navbar styles */
.navbar-inverse .navbar-nav>li>a:hover {
background-color: #2b2b2b;
color: #ffffff;
}
You forget to add id to div respone to collapse, just add it and the button work fine
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
Remove float: left; in class .navbar-inverse .navbar-nav > li > a and it will work
.navbar-inverse .navbar-nav > li > a {
color: #ffffff;
line-height: 60px;
padding: 0 30px;
text-decoration: none;
}
About two row menu in some viewport, i think you can add this
#media (min-width: 768px) and (max-width: 1000px) {
.container {width: auto}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,.1);
margin: 0 -15px !important;
overflow-x: hidden !important;
}
.navbar-collapse.collapse {
display: none !important;
}
.navbar-collapse.collapse.in {
display: block !important;
}
.navbar-header .collapse, .navbar-toggle {
display:block !important;
}
.navbar-header {
float:none;
}
.navbar-nav > li, .navbar-nav {
float: none !important;
}
.navbar-collapse.in {
overflow-y: visible !important;
overflow-x: hidden !important;
}
}
Demo
I have been playing around with bootstrap so build me a small personal page where I have a navbar that looks like this:
<body>
<nav class="navbar navbar-default navbar-fixed-top navbar-shrink">
<div class="container">
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#home">Jon Snow</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="page-scroll">
About Me
</li>
<li class="page-scroll">
Work
</li>
<li class="page-scroll">
Blog
</li>
<li class="page-scroll">
Contact Me
</ul>
</div>
</div>
</nav>
</body>
And its styled as follows:
body {
background-color:#2c3e50;
}
.navbar-fixed-top.navbar-shrink {
color:white;
padding: 10px 0;
background: rgba(0, 0, 0, .1);
}
But I get a white line at the navbar that looks like this:
How do I remove the white line and change the colors of the items in the Navbar to white?
Here is a JS Fiddle.
Here are the rules you can apply to remove borders (on all viewports) and change the color of the li items.
See working example Snippet.
body,
html {
background: #2c3e50;
}
.navbar.navbar-default {
padding: 10px 0;
background: rgba(0, 0, 0, .1);
border: none;
}
.navbar.navbar-default .navbar-nav > li > a,
.navbar.navbar-default .navbar-brand {
color: white;
}
.navbar.navbar-default .navbar-collapse {
border: none;
box-shadow: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-default navbar-fixed-top navbar-shrink">
<div class="container">
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#home">Jon Snow</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="page-scroll">
About Me
</li>
<li class="page-scroll">
Work
</li>
<li class="page-scroll">
Blog
</li>
<li class="page-scroll">
Contact Me
</ul>
</div>
</div>
Just add this to your styling:
.navbar { border: none!important; }
Bootstrap nav has a default border.
And the color:
.navbar-default .navbar-nav li a { color: #fff; }
This guy right here:
.navbar-default {
border-color: #e7e7e7;
}
Change that to none or the same color as your background color. Should do the trick.
EDIT
Sorry, I missed the second part of your question. This should set your text color in the nav bar:
.navbar-default .navbar-nav>li>a {
color: #fff;
}
Then you'll need a hover rule (or any other state):
.navbar-default .navbar-nav>li>a {
color: red;
}
The line is caused by the following CSS in Bootstrap
.navbar-default {
background-color: #f8f8f8;
border-color: #e7e7e7;
}
Overwrite this border-color with any color or no color you want.
For this links change the color with this
.navbar-default .navbar-nav > li > a{
color:**your color** !important;
}
You can do the hover, active, focus and visited colors for the links like this
.navbar-default .navbar-nav > li > a:hover{color: **your color** !important;}
.navbar-default .navbar-nav > li > a:active{color: **your color** !important;}
.navbar-default .navbar-nav > li > a:focus{color: **your color** !important;}
.navbar-default .navbar-nav > li > a:visited{color: **your color** !important;}
Hope that helps!