Remove dropdown link and show all of its items in navbar menu - css

I'm using Twitter Bootstrap and its responsive design for the typical Twitter Bootstrap navbar menu at the top.
In there i have a few links and a dropdown menu. When i resize my browser to 768px or less, it hen transforms into a new sort of nav menu.
This all works fine out of the box, but what i'd like to have is that the dropdown menu is also expanded.
What happends now is that the dropdown menu is still collapsed. When i open it, it then creates a scrollbar inside that menu container which i really don't like.
Here's a screenshot of what i mean:
Example: http://getbootstrap.com/examples/jumbotron/
How can i remove the open/close Dropdown link, and have all of its items listed inside that menu so that it doesn't create an ugly scrollbar on the side of the menu?

You could split your problem in three parts:
1. the scrollbar
By default the dropdown menu get a fixed (max) height of 340px (and a overflow-y:auto, see also: Twitter bootstrap 3 navbar navbar-right outside navbar-collapse).
You can undo this max-height by remove it (line 52 max-height: 340px;) from navbar.less and recompile Bootstrap. Or add some css after Bootstrap's css in your document:
#media(max-width:767px)
{
.navbar-collapse {
max-height: none;
}
}
Note when the height of the menu becomes the height of your screen, you can't scroll your content due to the fixed position of your navbar.
2. open the dropmenu on collapse
On the first sight you should add an open class to the dropmenu on collapse, but the clearmenus function of dropdown.js will remove this class. Adding a display:block will show the dropdown menu, but its state /display will be like non collapsed.
A solution will be to add a class with the same styles as the open class which won't be remove by the clearmenus.
$(document).on('click.bs.collapse.data-api', '[data-toggle=collapse]', function (e) {
$('.navbar-collapse .dropdown-toggle').parent().addClass('opened');
});
To give the opened class the same styles as the open class you will need to change your .less files and recompile Bootstrap after it.
in navbar.less (line: 215)
// Dropdowns get custom display when collapsed
.open .dropdown-menu, .opened .dropdown-menu {
in dropdown.less (line: 119)
// Open state for the dropdown
.opened, .open {
resize
With the above the dropdown menu stays visible after undo the collapse (by resizing the screen) to prevent this add some css after Bootstrap's CSS (you could also add this to your Less files):
#media(min-width:768px)
{
.nav > li.opened .dropdown-menu {display: none;}
.nav > li.open .dropdown-menu {display: block;}
}
styling of the links in the dropdown
Your navbar use navbar-inverse to style it (see also: https://stackoverflow.com/questions/18936357/using-multiple-navbars-with-twitters-bootstrap-3/18936358#18936358)
Navbar-inverse will be defined in navbar.less too. To set the link colors for the opend class too, use:
#media (max-width: #screen-xs-max) {
// Dropdowns get custom display
.open .dropdown-menu, .opened .dropdown-menu {
3. remove the dropdown link
css after Bootstrap's CSS:
#media(max-width:767px)
{
.nav > li > a.dropdown-toggle{display:none;}
}
Demo: http://jsfiddle.net/pgK4y/
See also: https://github.com/twbs/bootstrap/issues/10758

for the dropdown opened by default on mobile / small resolutions,
here is another approach using jquery that doesn't involve messing with less code or css.
tp://stackoverflow.com/a/23202921/1174172

Related

Centering tabs inside superfish navbar

Superfish navbars are great, but when you are looking at the rightmost tab, the second tier navbar starts at the far left. So if there are only a few tabs, it looks off-center and the user has to mouse all the way to the left. How can you center the tabs inside the superfish navbar?
Never mind, found the appropriate line to change in the css:
.sf-navbar > li > ul > li {
float: left;
}

Twitter Bootstrap navbar dropdown goes under slider image

I have a navbar build with Twitter Bootstrap 3.1.1. When on an iPhone or iPad the dropdown menu hides behind the slider image. It has a position absolute and a z-index of 1000.
When on a desktop it goes well, it goes over de slider images.
If you go to http://sitegeregeld.nl/. You see that the dropdown menu disappears behind the slider on the homepage on an iPad and iPhone. I don't see a sollution.
What goes wrong?
I was having the same problem(only hiding behind content on ipad), and this solved it:
.navbar {
position: static;
}
.navbar .nav > li {
z-index: 1001;
}
I'm using a bootstrap/wordpress framework that has it's own css style sheet that sets the navbar to position: relative.
found answer here: z-index issue with twitter bootstrap dropdown menu

Twitter Bootstrap Navbar Dropdown Styling

I am in the process of styling the top navbar but can not see how to remove the top caret on the dropdown panel (please see image below). Please let me know if you can help. Thanks
You can remove it by overriding the Bootstrap CSS like this..
/* remove the triangle */
.navbar .nav>li>.dropdown-menu:before,.navbar .nav>li>.dropdown-menu:after {
content: none;
}
Working example: http://bootply.com/66576

Keeping parent nav background active when on child page - CSS

This seems like a fairly straightforward thing but can't find any tutorial on it.
I have a top menu that changes background colour then one of the menu items is selected. The CSS looks like this:
.nav > li > a:hover,
.nav > li > a.selected {
background-color: #F7A379;
}
However some pages have a side menu, with a class .left-nav and when I click on those links the background styling disappears from the parent nav. Is it possible to keep the styling above when the child page is selected? If so, what would the CSS need to be?

overflow style in menu display

In my menu I use overflow:hidden and menu width to display my menu and hide text if the screen size becomes smaller. However it hides also the submenu at the same time
By submenu I mean the menu of level > 2
So if I hover an item in the menu bar, I can get the menu display but if that menu contains some subitems then they won't display at all. But when I delete overflow:hidden in my css that is being applied for ul/li elements to create the menu, they show up but the text looks ugly especially if it is longer than the menu width
I think using this should work:
ul{
overflow:visible;
}
ul.li{
overflow:hidden;
}
ul.li.ul{
overflow:visible;
}
ul.li.ul.li{
overflow:hidden;
}
Of course you will have to apply it to your own stylesheet. I am not totaly sure this will work, becouse i cant see your code/stylesheet from here.

Resources