The problem is the drop-down behavior (here's the codepen to the problematic html, the original layout was taken from here).
<header class="pb-3">
<nav class="navbar navbar-expand-md navbar-light bg-white border-bottom">
<div class="d-flex w-100 navbar-collapse">
<ul class="navbar-nav me-auto mb-2 mb-md-0">
<li>
<div style="width: 100px; height: 100px">
<a href="#">
<img src="../static/store_logo.png" alt="logo" />
</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle d-none d-md-block fw500" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Product categories
</a>
<ul class="dropdown-menu rounded-0 border-0">
<a href="#">
<li>Foo</li>
</a>
<a href="#">
<li>Bar</li>
</a>
<a href="#">
<li>Baz</li>
</a>
</ul>
</li>
</ul>
</div>
</nav>
</header>
In the original source the problem is hidden by the fact that a logo image/placeholder inside the nav > .navbar ul is tiny. When I used a larger image, it becomes manifest (I used a div with fixed 100 by 100 px to mimic it in the pen).
The problem is the behavior of a drop-down in the same nav. The list of items in .dropdown-menu (ul) doesn't attach to the bottom of the .dropdown-toggle element - instead it's attached to the bottom of the .navbar-nav ul. Which, naturally, is affected by the size of the li containing the image/placeholder.
Being a css noob, I don't know what is the real cause of the problem. Is it a conflict
beyween some of the bootstrap classes? I even tried adding a z-index to the .dropdown-menu ul, to no avail. Basic dropdown example in the Bootstrap docs doesn't seem to require any additional tweaks - but there's no navs/navbars involved in there (not to mention a dozen other parent elements).
Thank you all for your time!
Please add this custom css and check agian.
body .navbar-expand-md .navbar-nav .dropdown-menu {
top: 30px !important;
}
less hacky solution would be:
.navbar-expand-md .navbar-nav .dropdown-menu {
position: static;
}
====== UPDATE ============
well this solution has an issue of it's own - the entire content of the .navbar is shifting because of the 'static' dropdown menu; the accepted answer doesn't have that problem. CSS dark magic =)
Related
This is similar to other questions posted, but a bit more specific.
My goal is to create a split navbar using CSS (pure or using bootstrap), with login and signup buttons aligned to the right and other buttons to the left. On XL screens, I have the login and signup buttons change from inline-block to block display, which makes them take up two lines each. Each consists of a font awesome icon and text. With this simple change, I'm having a lot of trouble with vertically aligning the other buttons. The block buttons are centered vertically in the navbar, but the others are too high.
All flexbox-based solutions have had the side effect of removing the right-alignment of the login and signup buttons. This includes any bootstrap classes like d-flex, adding any align properties to the css file..
I could redesign the navbar to have the right-aligned items in a secondary navbar as in the solution here: bootstrap navbar floating left and right but I am pretty curious about solving / understanding this issue (and being able to implement this in the simplest way possible).
Here's how I have the html structure:
<div class="container-fluid">
<div class="row no-gutters flex-row">
<ul class="">
<li class=""> Map</li>
...
<li class="dropdown">
...
</li>
<li class="nav navbar-right " id="signup-btn">
<span class="fa fa-user"></span><span class="d-none d-sm-inline d-xl-block">Sign Up</span>
</li>
<li class="nav navbar-right " id="login-btn">
<span class="fa fa-sign-in"></span><span class="d-none d-sm-inline d-xl-block" >Log In</span>
</li>
</ul>
</div>
</div>
Custom CSS for these elements:
li {
float: left;
}
li a, .dropbtn {
display: inline-block;
text-align: center;
padding: .9rem .9rem;
}
#login-btn{
float: right; !important;
}
#signup-btn {
float: right; !important;
}
#navbar li {
vertical-align: center;
}
What this looks like:
If I try some of the flex solutions posted eg, here Bootstrap NavBar with left, center or right aligned items, can't split the navbar any more:
use "text-right" class for container div - in bootstrap
If I correctly understood your task you can do like this:
Split nav into 2 blocks and move them with
.nav {
justify-content: space-between;
}
Set blocks' height equal 100% of the parent
Use 'align-items: center' inside of them
.nav__list, .nav__buttons {
height: 100%;
display: flex;
align-items: center;
}
I've created pen. I think it'll help you.
https://codepen.io/dimaaan21/pen/WNvbEvM
The other question does provide the guidance needed to achieve left and right Navbar items with text & icons.
Just use 2 navbar-nav's and justify-content-between...
<nav class="navbar navbar-dark navbar-expand justify-content-between">
<div class="container-fluid">
<ul class="navbar-nav">
<li class="nav-item text-center">
<span class="fa fa-map"></span><span class="d-none d-sm-inline d-xl-block px-1">Map</span>
</li>
<li class="nav-item dropdown text-center">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="fa fa-list"></span><span class="d-xl-block d-none"></span><span class="d-none d-sm-inline px-1">Dropdown</span> </a>
...
</li>
</ul>
<ul class="nav navbar-nav ml-auto">
<li class="nav-item text-center" id="signup-btn">
<span class="fa fa-user"></span><span class="d-none d-sm-inline d-xl-block px-1">Sign Up</span>
</li>
<li class="nav-item text-center" id="login-btn">
<span class="fa fa-sign-in"></span><span class="d-none d-sm-inline d-xl-block px-1">Log In</span>
</li>
</ul>
</div>
</nav>
https://codeply.com/go/kTGlK9Axdk/left-right
this is a bad way to solve the problem. It's better to use flexbox instead of float.
for example:
<div class="parent-box">
<div>
Map
...
</div>
<div>
<span class="fa fa-user"></span><span class="d-none d-sm-inline d-xl-block">Sign Up</span>
<span class="fa fa-sign-in"></span><span class="d-none d-sm-inline d-xl-block" >Log In</span>
</div>
</div>
.parent-box {
display: flex;
align-items: center;
justify-content: space-between;
}
I'm having a bit of a problem with the Bootstrap nav I've placed on a website I'm making.
When collapsed on smaller screens, the drop down navigation menu doesn't span 100% of the screen - It looks as if there's a 1px gap on either side of the menu and I can't seem to figure out how to fix this.
** EDIT **
Due to bad markup in my original post - I've updated this (still having probelems, but this represents my problem better) at JSFIDDLE
<div class="navbar navbar-custom">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navigation">
<span class="fa fa-bars fa-2x"></span> Menu</button>
<span class="logo"> Logo</span>
</div>
<div class="collapse navbar-collapse" id="navigation">
<ul class="nav navbar-nav navbar-right">
<li>Book A Repair </li>
<li>About </li>
<li>How it Works </li>
<li>Testimonals </li>
<li>Contact </li>
</ul>
</div>
</div>
It's happening because of the Bootstrap margin on the .navbar-collapse.. which is a negative margin of 15px. Just move it out a pixel on each side:
.navbar-custom .container >.navbar-collapse {
margin-right: -16px;
margin-left: -16px;
}
Bootply
I have a bootstrap tabs, and some of them have very long text, and it creates ugly space between tabs and content. How can I set the other tabs to have the same size as the biggest one?
<div class="tabs">
<ul class="nav nav-tabs nav-justified">
<li>
<a href="#" class="text-center">
<i class="fa fa-wifi"/> Not that long</a>
</li>
<li>
<a href="#" class="text-center">
<i class="fa fa-map-marker"/> Something really really really long</a>
</li>
<li>
<a href="#" class="text-center">
<i class="fa fa-map-marker"/> Not that long</a>
</li>
<li class="active">
<a href="#" class="text-center">
<i class="fa fa-star"/> Not that long</a>
</li>
</ul>
<div class="tab-content"></div>
</div>
Found a solution!
<style>
.nav-tabs{
display: flex;
}
.nav-tabs li {
display: flex;
flex: 1;
}
.nav-tabs li a {
flex: 1;
}
</style>
You can either make them all taller or you can shorten the name of the tab that's too long. Tab names shouldn't really be very long anyways.
If you can't use flexbox (which is not supported by older browsers), your only choice is to set all the tabs as tall as the tallest one explicitly with a pixel height. Flexbox is a great and sadly not yet fully usable solution to this kind of problem. Without it, there's no flexible way to accomplish this.
So i'm working with Twitter's Bootstrap for the first time and I'm trying to change the color of the text inside the dropdown menus once they have collapsed. (if that makes sense)
I used this site (<<<--- link to CSS i am using) to help with some CSS but i can't seem to find the right code block that changes the color of the correct text.
When you compress the webpage so it shows the collapse menu and go to the Dropdown list, you will see that the blue background transfers over to the dropdown menu items, but the font-color is black making it very hard to read. I want this font to be white.
<nav class="navbar navbar-custom" role="navigation">
<!-- 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="#">ATR Notary</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="dropdown">
<a href="~/Order/Index" class="dropdown-toggle"
data-toggle="dropdown">Orders <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>View Orders</li>
<li>Add Order</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="~/Notary/Index" class="dropdown-toggle"
data-toggle="dropdown">Notaries <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>View Notaries</li>
<li>Add Notary</li>
</ul>
</li>
</ul>
#Html.Partial("_LoginPartial")
</div><!-- /.navbar-collapse -->
</nav>
You should be able to use this CSS..
/*-- change navbar dropdown color --*/
.navbar-default .navbar-nav .open .dropdown-menu>li>a,.navbar-default .navbar-nav .open .dropdown-menu {
background-color: #3344ff;
color:#ffffff;
}
Demo: http://www.bootply.com/113750
Apply simple css and you are done
See this example:
.navbar{height:70px; padding-top:20px; }
will change height and padding of navbar - that is outter container
.dropdown-menu{background:rgba(0,0,0,0.5); color:white; }
will change background color of dropdown-menu - that is ul under dropdown link.
All we have to understand the structure of navbar.
.dropdown-menu li>a{color:white; }
.dropdown-menu>li{padding:5px; border-bottom:1px solid white;border-left:1px
solid white;border-right:1px solid white }
.dropdown-menu li>a:hover{background:white; }
previous answer is saying the same thing pretty much, but their syntax and commenting was a little confusing for me, so possibly it confused others too...
you're first calling out the 'dropdown-menu' class, then the 'li' html element within that class, then, the 'a' html element nested within the 'li' element, so CSS looks like this:
.dropdown-menu li a {
color: white;
}
I'm creating a Site using Twitter Bootstrap 2.0.4 + bootstraps responsive.css. What I don't know is: Is it possible to have a logo appearing at the top left of the site and the navbar appearing on the right of the logo (but fixed at top)? While changing Sizes, the Logo should then appear on top of the navbar.
Would be really nice to get an answer for I haven't found anything helpful yet.
Greetings,
Dominik
edit: Here's a picture describing what I want to achieve: http://i.imgur.com/HX3ZM.png
Logo on the left, then navbar.
Okay, I got it. I used the fixed navbar, which didn't work as expected. You have to use a static navbar. Then you could just use the row / scaffolding system from bootstrap.
Example code for a logo left from the navbar:
<div class="row-fluid">
<div class="span3">
<p><img src="/sites/img/your_logo.png" alt="Logo" class="responsive-logo"></p>
</div>
<div class="span9">
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<div class="btn-group pull-right">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
<i class="icon-user"></i> Username
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>Profile</li>
<li class="divider"></li>
<li>Sign Out</li>
</ul>
</div>
<div class="nav-collapse">
<ul class="nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</div>
</div>
</div><!-- end navbar -->
</div><!-- end span8 -->
</div><!-- end row -->
To make my Logo responsive, I added the following css rules:
.responsive-logo {
max-width: 100%;
height: auto;
border: 0;
padding-top: 10px;
}
Yes, sure—you will need to re-structure your document to place (for example) a div with the span4 class above the navbar.
Below that, have the navbar code and remove the branding elements (which usually house your logo). My assumption leads me to believe you want something like this:
If you can be a bit more specific about what you want, and/or provide the relevant parts (HTML) of your site, I can likely give some more direction.