I am working on a Bootstrap 3 site and have everything working except the main menu. It has a hair trigger when it comes to resizing and truncates well in advance of the overall page sizing and quickly drops the last two navigation items to the next row, disrupting the slider, before it adjusts to the mobile navigation.
The page can be found here.
The HTML is as follows:
<!-- Navigation -->
<div class="navbar navbar-default" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" 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>
</div><!-- navbar-header -->
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>Our Attorneys</li>
<li>Business Ligitagion</li>
<li>Personal Injury</li>
<li>Verdicts & Settlements</li>
<li>Client Testimonials</li>
<li>Map & Directions</li>
</ul>
</div><!--/.nav-collapse -->
</div><!-- container -->
</div><!-- navbar -->
The CSS:
/* #group navigation */
.navbar {
position: relative;
min-height: 35px;
margin-bottom: 0;
}
.navbar-default {
background-color: #9d2024;
border: none;
height: 25px;
}
#media (max-width: 767px) {
.navbar-default {
min-height:50px;
}
}
.navbar-default .navbar-brand {
color: #fff;
}
.navbar-default .navbar-brand:hover,
.navbar-default .navbar-brand:focus {
color: #fff;
border-bottom: 6px solid #fff;
}
.navbar-default .navbar-text {
color: #fff;
}
.navbar-default .navbar-nav > li > a {
color: #fff;
padding: 3px 10px;
margin: 5px 0 0 0;
border-right: 1px solid #fff;
font-family: trebuchet ms;
text-transform: uppercase;
}
.navbar-default .navbar-nav > li:last-child > a {
border: none;
}
.navbar-default .navbar-nav > li > a:hover,
.navbar-default .navbar-nav > li > a:focus {
color: #fff;
border-bottom: 4px solid #fff;
}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:hover,
.navbar-default .navbar-nav > .active > a:focus {
color: #fff;
border-bottom: 4px solid #fff;
background-color: #9d2024;
}
If I remove the container the navigation floats to the far left and does not flow with the page. I could use some insight for getting the navigation to resize properly without truncating.
You need yo use right bootstrap structure.
Problem is here:
row bannerand row slider-bg divs classes. Just remove row name and all need to work.
Error reason of start building a bootstrap is put a row of parent of container class. Container is first wrapping class in bootstrap, then comes row and then cols
For menu use smaller font size or inner li, a paddings.
Related
I have a complex scenario, please have a look at the below screenshots.
When navbar is collapsed on the smaller screen, and I click on the button to expand, the following screen comes out, and it will go only if I click on any of the tabs( about, services etc), click on the top right icon for navbar, wont affect and the drop down menu does not go back.
The second scenario (please refer to the image below), when I expand the screen back from the smaller one, navbar is totally messed up. I dont know what I am doing wrong. Heres the css of my entire navbar.
CSS
.navbar {
height: 80px;
background-color: transparent;
border: none;
color: white;
z-index: 100;
transition: background-color 1s ease 0s;
}
.navbar-default .navbar-brand {
margin-top: 10px;
color: white;
}
.navbar-default .navbar-brand:hover {
color: #C57ED3;
border: 1px solid #C57ED3;
}
.navbar-default .navbar-nav > li > a {
color: white !important;
margin: 10px 5px 5px 5px;
}
.navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:active, .navbar-default .navbar-nav > li > a:focus {
color: #C57ED3;
border: 1px solid #C57ED3;
}
.navbar-default .navbar-nav > li > a:visited {
color: #C57ED3;
text-decoration: none;
}
.navbar-default .navbar-nav > .active > a, .navbar-default .navbar-nav > .active > a:hover, .navbar-default .navbar-nav > .active > a:focus {
background-color: transparent;
color: #C57ED3;
}
.navbar-default .navbar-toggle {
border-color: #C57ED3;
}
.navbar-default .navbar-toggle:hover, .navbar-default .navbar-toggle:focus {
background-color: #490D40;
}
.navbar-default .navbar-toggle .icon-bar {
color: #C57ED3;
background-color: #C57ED3;
}
.navbar-default .navbar-collapse.collapse.in ul {
background-color: #490D40;
}
html
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<img src="img/logo.png" width="130px;" height="50px;" style="margin-top: 20px;">
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li>About</li>
<li><a href="services" >Services</a></li>
<li><div class="dropdown" >
<button class="dropbtn">Work</button>
<div class="dropdown-content">
Web Development
Students
Content Writing
</div>
</div>
</li>
<li><a href="#contact" >Contact</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
This is my first attempt on creating a bootstrap menu, and I am stuck on the following issues. I tried different solutions suggested on similar questions, but with no success ☹
When collapsed I want the text: This is a Button to next to the button “button1”.
I’ve tried playing around with inline styling but I cannot get the 2 elements to stay on one line.
If I manage to display them on the same line, how do I make the text element to have the same left margin as the dropdown element below when collapsed?
I am not sure why the text & button element do not have the same left-margin as the dropdown below them.
Here is a copy of my code: https://jsfiddle.net/b512zesq/
thanks!
.navbar {
min-height: 80px;
background: #ee4035;
border-width: 0px;
border-radius: 0px;
color: blue;
}
.navbar a {
color: white!important;
}
.navbar-brand {
padding: 0 15px;
height: 80px;
line-height: 80px;
color: white;
}
.navbar-toggle {
/* (80px - button height 34px) / 2 = 23px */
margin-top: 23px;
padding: 9px 10px !important;
}
.navbar-btn {
/* (80px - button height 34px) / 2 = 23px */
margin-top: 18px;
margin-right: 30px;
padding: 9px 9;
background: #f37736;
border-width: 0px;
height: 35px;
width: 150px;
}
.navbar-text {
margin-top: 28px;
color: white;
}
.nav.navbar-nav.navbar-right li a {
color: white;
}
.dropdown-menu {
background: #ee4035;
}
.dropdown-menu>li>a:hover,
.dropdown-menu>li>a:focus {
background-color: #d6392f;
}
.navbar-default .navbar-nav>li>a:hover,
.navbar-default .navbar-nav>li>a:focus {
color: #ffffff;
}
.navbar-default .navbar-nav>li>.dropdown-menu {
background-color: #ee4035;
}
.navbar-default .navbar-nav>li>.dropdown-menu>li>a {
color: #ffffff;
}
.bar-nav>li>.dropdown-menu>li>a:hover,
.navbar-default .navbar-nav>li>.dropdown-menu>li>a:focus {
color: #ffffff;
background-color: #d6392f;
}
.navbar-default .navbar-nav>li>.dropdown-menu>li>.divider {
background-color: blue;
}
.navbar-default .navbar-nav>.active>a,
.navbar-default .navbar-nav>.active>a:hover,
.navbar-default .navbar-nav>.active>a:focus {
color: #ffffff;
background-color: #d6392f;
}
.navbar-default .navbar-nav>.open>a,
.navbar-default .navbar-nav>.open>a:hover,
.navbar-default .navbar-nav>.open>a:focus {
color: #ffffff;
background-color: #d6392f;
}
.navbar-default .navbar-toggle {
border-color: #d6392f;
}
.navbar-default .navbar-toggle:hover,
.navbar-default .navbar-toggle:focus {
background-color: #d6392f;
}
.navbar-default .navbar-toggle .icon-bar {
background-color: #ffffff;
}
.navbar-default .navbar-collapse,
.navbar-default .navbar-form {
border-color: #ffffff;
}
.navbar-default .navbar-link {
color: #ffffff;
}
.navbar-default .navbar-link:hover {
color: #ffffff;
}
/*RESPONSIVE*************************************************/
#media (min-width: 768px) {
.navbar-nav>li>a {
/* (80px - line-height of 27px) / 2 = 26.5px */
padding-top: 26.5px;
padding-bottom: 26.5px;
line-height: 27px;
}
}
/**END OF RESPONSIVE********************************************/
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">logo</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li class="inline"><span class="navbar-text" style="color:white"><strong>this is a button</strong></span></li>
<li><a class="btn btn-danger navbar-btn" href="{$rlBase}/add-listing.html" role="button">button 1</a></li>
<form class="navbar-form navbar-left" style="padding:0px; border-top-width:0px;"></form>
<li class="dropdown">
<a class="dropdown-toggle" id="user-navbar" data-toggle="dropdown" href="{$rlBase}/login.html"><span class="glyphicon glyphicon-user"></span> USERNAME<span class="caret"></a>
</div>
</div>
</nav>
You could style your parent <ul> with display: inline-flex and put the list-item with your dropdown outside of it. That could cause compatibility issues, however.
Just give your list item a padding-left of 15px. The dropdown link has a default padding-left of 15px (you can find that in the navs.less file on line 23).
I am trying to add padding to my Bootstrap website. However, when i resize the browser, the navigation bar messes up completely instead of staying fixed. Here is a link for pictures http://imgur.com/a/YmyEW
html code:
<nav class="nav`bar navbar-custom">
<div class="container2">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">logo</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li>WHO</li>
<li>WHAT</li>
<li>WHERE</li>
</ul>
</div>
</div>
css code:
`body{
padding-left: 200px;
padding-right: 200px;
}
.navbar-custom {
background-color:transparent;
color:#000;
border-radius:0;
padding-top: 50px;
}
.navbar-custom .navbar-nav > li > a {
color:#000;
}
.navbar-custom .navbar-nav > .active > a {
color: #000;
background-color:transparent;
}
.navbar-custom .navbar-nav > li > a:hover,
.navbar-custom .navbar-nav > li > a:focus,
.navbar-custom .navbar-nav > .active > a:hover,
.navbar-custom .navbar-nav > .active > a:focus,
.navbar-custom .navbar-nav > .open >a {
text-decoration: none;
background-color: #ff0000;
}
.navbar-custom .navbar-brand {
color:#eeeeee;
}
.navbar-custom .navbar-toggle {
background-color:#eeeeee;
}
.navbar-custom .icon-bar {
background-color:#33aa33;
}
.container {
padding-top: 70px;
padding-bottom: 70px;
font-family: 'Bree Serif', serif;
font-size: 20em;
}
.footer-right{
padding-top: 70px;
font-family: 'Bree Serif', serif;
}`
I see some problems with your code formatting but got the idea. What you need the most ist the class navbar-fixed-top added to your navbar so it'll be always on top. And I also suggest to make custom classes instead overriding the container class completely. Better would be container custom-container - so it'll still got it's basic functionality and additionally your changes. I also see that you're using the class container2 which isn't defined and therefore can't work as a container.
Working Example
HTML
<nav class="navbar navbar-custom navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li>WHO</li>
<li>WHAT</li>
<li>WHERE</li>
</ul>
</div>
</div>
</nav>
<div class="container custom-container">
<div class="text-center">
<h1>Bootstrap starter template</h1>
<p class="lead">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p>
</div>
</div><!-- /.container -->
CSS
body{
padding-top: 100px;
padding-left: 200px;
padding-right: 200px;
}
.navbar-custom {
background-color:transparent;
color:#000;
border-radius:0;
padding-top: 50px;
}
.navbar-custom .navbar-nav > li > a {
color:#000;
}
.navbar-custom .navbar-nav > .active > a {
color: #000;
background-color:transparent;
}
.navbar-custom .navbar-nav > li > a:hover,
.navbar-custom .navbar-nav > li > a:focus,
.navbar-custom .navbar-nav > .active > a:hover,
.navbar-custom .navbar-nav > .active > a:focus,
.navbar-custom .navbar-nav > .open >a {
text-decoration: none;
background-color: #ff0000;
}
.navbar-custom .navbar-brand {
color:#eeeeee;
}
.navbar-custom .navbar-toggle {
background-color:#eeeeee;
}
.navbar-custom .icon-bar {
background-color:#33aa33;
}
.container-custom {
padding-top: 70px;
padding-bottom: 70px;
font-family: 'Bree Serif', serif;
font-size: 2em;
}
The <body> is directly under the <head> though. So, it would mess up your container. Michael Cooker is pointing you in a good direction.
I want to change the color of the "Home" "Spin" "Social Media" but no clue how. I spent a few days on figuring out how to change the navigation background but have no clue on the color because I only want to change the grey to white and change the hover color as well. I can change the color to white but then the hover color would be ignored. Is there an intended way to do this?
Here is how I changed the navigation background color.
.navbar-inverse {
background-color:#66ccff;
background-image: none;
background-repeat: no-repeat;
}
incase it helps :D
This is a relatively comprehensive breakdown of the navigation components and often changed properties. I would suggest using a custom class in your main navbar div (navbar-custom is used for this example) to avoid changing the base CSS directly.
/***Navbar Background Color, Border Removed ,Border Radius Sqaure***/
.navbar.navbar-custom {
background: #66ccff;
border: none;
border-radius: 0;
}
/***Link Color***/
.navbar.navbar-custom .navbar-nav > li > a {
color: #f00;
}
/***Link Color Hover Statr***/
.navbar.navbar-custom .navbar-nav > li > a:hover {
color: #ff0;
}
/***Link Background and Color Active State***/
.navbar.navbar-custom .navbar-nav > .active,
.navbar.navbar-custom .navbar-nav > .active > a,
.navbar.navbar-custom .navbar-nav > .active > a:hover,
.navbar.navbar-custom .navbar-nav > .active > a:focus {
background: #DBF022;
color: #66ccff;
}
/***Navbar Brand Link Color***/
.navbar.navbar-custom .navbar-brand {
color: #f00;
}
/***Navbar Brand Link Color Hover State***/
.navbar.navbar-custom .navbar-brand:hover {
color: #ff0;
}
/***Dropdown Background Active State***/
.navbar.navbar-custom .nav li.dropdown.open > .dropdown-toggle,
.navbar.navbar-custom .nav li.dropdown.active > .dropdown-toggle,
.navbar.navbar-custom .nav li.dropdown.open.active > .dropdown-toggle {
background: #DBF022;
color: #f00;
}
/***Dropdown-menu Background Color***/
.navbar.navbar-custom .dropdown-menu {
background: #66ccff;
border: none;
}
/***Dropdown-menu Color***/
.navbar.navbar-custom .dropdown-menu > li > a {
color: #f00;
}
/***Dropdown-menu Color Hover and Focus State***/
.navbar.navbar-custom .dropdown-menu > li > a:hover,
.navbar.navbar-custom .dropdown-menu > li > a:focus {
color: #ff0;
background: #f00;
}
/***Toggle Button***/
.navbar.navbar-custom .navbar-header .navbar-toggle {
border-color: #f00;
}
/***Toggle Button Hover and Focus State***/
.navbar.navbar-custom .navbar-header .navbar-toggle:hover,
.navbar.navbar-custom .navbar-header .navbar-toggle:focus {
background: #f00;
border: #f00;
}
/***Collapse Borders***/
.navbar.navbar-custom .navbar-collapse {
border: none;
}
#media (max-width: 767px) {
.navbar.navbar-custom li.dropdown .dropdown-menu > li > a {
color: #f00;
}
/***Dropdown-menu Color Hover and Focus State***/
.navbar.navbar-custom li.dropdown .dropdown-menu > li > a:hover,
.navbar.navbar-custom li.dropdown .dropdown-menu > li > a:focus {
color: #ff0;
background: #f00;
}
}
<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.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-inverse navbar-custom">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <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="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active">Link <span class="sr-only">(current)</span>
</li>
<li>Link
</li>
<li class="dropdown"> Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action
</li>
<li>Another action
</li>
<li>Something else here
</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
.navbar .nav > li > a
that is the target you are seeking!
to customize use the below selectors...
(note, you won't need !important if your customizations are loaded after the bootstrap css, ie your <link href="..my-customizations.css" /> loaded after <link href="...cdn...bootstrap.min.css" />)
/* links */
.navbar-inverse .navbar-nav>li>a {
color: red!important;
}
/* active, focus or hover links */
.navbar-inverse .navbar-nav>.active>a,
.navbar-inverse .navbar-nav>.active>a:focus,
.navbar-inverse .navbar-nav>.active>a:hover {
color: red!important;
}
jsfiddle example
For some reason when I click the pancake button, I have been able to get the menu to display as a block using the z-index but on the list of elements of the menu. So the "block" is not the entire navbar but rather just the section that lists the links to the other pages and I ma not sure why. I have tried to drill into css and use block elements with no luck.
Here is the html for the navbar:
<nav class="navbar navbar-default">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
data-target=".navbar-collapse" aria-expanded="false">
<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="/hug/">Hug a Tree</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav pull-right">
<li>about</li>
{% if user.is_authenticated %}
<li>profile</li>
<li>f<span style="color:#e48666">a</span>vourites</li>
<li>logout</li>
{% else %}
<li>register</li>
<li>login</li>
{% endif %}
</ul>
</div>
</nav>
And the css:
.navbar-default {
background-color: #fff;
border-color: #e9e7b6;
margin: 25px;
height: 100px;
}
.navbar-default .navbar-text {
font-family: 'Raleway', sans-serif;
}
.navbar-default .navbar-nav > .active > a, .navbar-default .navbar-nav > .active > a:hover, .navbar-default .navbar-nav > .active > a:focus {
font-family: 'Raleway', sans-serif;
color: #5aa47d;
}
.navbar-default .navbar-nav > .open > a, .navbar-default .navbar-nav > .open > a:hover, .navbar-default .navbar-nav > .open > a:focus {
font-family: 'Raleway', sans-serif;
color: #5aa47d;
}
.navbar-default .navbar-link {
font-family: 'Raleway', sans-serif;
color: #5c606b;
}
.navbar-default .navbar-link:hover {
font-family: 'Raleway', sans-serif;
color: #5aa47d;
}
.navbar-toggle {
margin-top: 33px;
}
ul.nav.navbar-nav.pull-right{
z-index: 2;
position: relative;
}
.nav.navbar-nav.pull-right li{
display: block;
z-index: 1;
background-color: #fff;
}
/*** navbar - icon ***/
img.brand {
display: block;
margin-left: auto;
margin-right: auto;
}
/*** navbar - brand/logo ***/
.navbar-default .navbar-brand{
font-family: 'Oswald', sans-serif;
float: left;
color: #426085;
padding: 35px 15px 0px 25px;
height: 50px;
font-size: 30px;
line-height: 25px
}
.navbar-default .navbar-brand:focus, .navbar-default .navbar-brand:hover{
color: #5aa47d;
}
/*** navbar - list ***/
.navbar-default .navbar-nav > li > a {
font-family: 'Raleway', sans-serif;
font-size: 16px;
color: #5c606b;
}
.navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus, .navbar-default .navbar-nav > li > a:active {
font-family: 'Raleway', sans-serif;
color: #5aa47d;
}
.navbar-nav>li>a {
padding-top: 39px;
padding-right: 20px;
}
Any insight would be great.
Thanks.
I think this is what you're trying to do jsfiddle
pull-right was deprecated as of v3.1.0 and replaced with navbar-right.
Alexis Jensen Hi there. You are using a class pull-right in this line of code...
<ul class="nav navbar-nav pull-right">
If you remove the pull-right class it will expand across.
Is that all you were wanting here?