bootstrap navbar always collapsed but when expanded, need to show the width as it is shown when the screen width is shorter - twitter-bootstrap-3

I did the following to make my navigation bar always collapsed. However, when you click on it, it's taking up the whole width of the screen. And when you click on Menu, the dropdown is occupying a small part only.
What I want is when I click the navigation icon in the right, it will expand but will not take the whole width of the screen. Instead I want it to display as it displays when the screen width is small just like in the picture
#media (max-width: 2000px) {
.navbar-header {
float: none;
}
.navbar-left,.navbar-right {
float: none !important;
}
.navbar-toggle {
display: block;
}
.navbar-collapse {
border-top: 1px solid transparent;
box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}
navbar-fixed-top {
top: 0;
border-width: 0 0 1px;
}
.navbar-collapse.collapse {
display: none!important;
}
.navbar-nav {
float: none!important;
margin-top: 7.5px;
}
.navbar-nav>li {
float: none;
}
.navbar-nav>li>a {
padding-top: 10px;
padding-bottom: 10px;
}
.collapse.in{
display:block !important;
}
}
This is what I need:

Ok, so I'm still not sure why you want a menu inside a menu, but you could use a nav instead of a dropdown if you're looking for full width. The dropdown has a width of 160px. Use collapse to show/hide the submenu.
<a href="#" data-toggle="collapse" data-target="#menu1" role="button" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-menu-hamburger" aria-hidden="true"></span>
<span>Menu</span>
</a>
<ul class="nav collapse" aria-labelledby="menu" id="menu1">
<li>
<div class="menu-content">
<ul class="nav nav-stacked">
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ul>
</div>
</li>
</ul>
http://bootply.com/cv3l6gxjZn

Related

Can I use Bulma dropdown in Bulma tabs?

I'm using Nuxt.js and Bulma. I'm making navigation using Bulma tabs(https://bulma.io/documentation/components/tabs/).
I wanna insert Bulma dropdown(https://bulma.io/documentation/components/dropdown/#hoverable-or-toggable). But it doesn't work in middle of Tabs.
I know who wanna use Bulma dropdown needs to use javascript, so I use it. But it doesn't work.
How can i fix it?
To get a dropdown working inside Bulma's tabs, you need to adjust the overflow CSS in the tabs div. I'm not sure why I had to set overflow-x and overflow-y to get this working properly, but I did.
When the dropdown is active:
overflow-x : visible;
overflow-y : visible;
When the dropdown is not active, reset to their defaults:
overflow-y : hidden;
overflow-x : auto;
Yes you can with a little amount of fiddling
There are mainly 2 problems :-
Problem 1
As bulma tabs container is flexbox, and the list of tabs are child of this flexbox, the dropdown will not be visible as it overflows out of flexbox container.
If you add overflow-y:visible to tabs container div, scrolling will happen which is not the behaviour we need
Solution
To fix this, the contents to be shown on tab selection should also come inside the tabs container as second child, so that dropdown button/link in list of
tabs has the space to show the dropdown when clicked/hovered.
#tab-container {
flex-direction: column;
height: 500px;
width: 100%
}
#content-child {
flex-grow: 1;
width: 100%
}
#list-child {
flex-grow: 0; //should be set to 0 as it will take up vertical space (it is set to 1 in bulma)
width: 100%;
}
Problem 2
When dropdown is used within bulma tabs, the anchor tags in dropdown gets styled by those specified for anchor tags in tabs.This is one of the main issue.
The dropdown shown thus will be styled very differently.
Solution
Bulma dropdown also allows us to insert div inside.
We can make use of this to overcome problem 1.
Just add this css for divs inside dropdown so as to make it behave like links.
div.dropdown-item.is-active {
background-color: rgba(55, 122, 195, 0.95);
color: #fff;
}
div.dropdown-item {
padding-right: 3rem;
text-align: left;
white-space: nowrap;
width: 100%;
cursor: pointer;
text-decoration: none;
}
div.dropdown-item:hover {
background-color: whitesmoke;
color: #0a0a0a;
}
Complete solution can be seen below and you can change as required for your use case.
div.dropdown-item.is-active {
background-color: rgba(55, 122, 195, 0.95);
color: #fff;
}
div.dropdown-item {
padding-right: 3rem;
text-align: left;
white-space: nowrap;
width: 100%;
cursor: pointer;
text-decoration: none;
}
div.dropdown-item:hover {
background-color: whitesmoke;
color: #0a0a0a;
}
#content-child {
flex-grow: 1;
width: 100%
}
#tab-container {
flex-direction: column;
height: 500px;
width: 100%
}
#list-child {
flex-grow: 0;
width: 100%;
}
<link href="https://cdn.jsdelivr.net/npm/bulma#0.8.1/css/bulma.min.css" rel="stylesheet" />
<div class="tabs is-boxed" id="tab-container">
<ul id="list-child">
<li><a>Pictures</a></li>
<li><a>Music</a></li>
<li><a>Videos</a></li>
<li><a>Documents</a></li>
<li class="dropdown is-active">
<div class="dropdown-trigger">
<a class="has-text-right custom-padding" aria-haspopup="true" aria-controls="dropdown-menu">
Drop Down
</a>
</div>
<div class="dropdown-menu" id="dropdown-menu" role="menu">
<div class="dropdown-content">
<div class="dropdown-item">Dropdown item</div>
<div class=" dropdown-item">Other dropdown item</div>
<div class=" dropdown-item is-active">Active dropdown item</div>
<div class=" dropdown-item">Other dropdown item</div>
<hr class="dropdown-divider" />
<div class=" dropdown-item">With a divider</div>
</div>
</div>
</li>
</ul>
<div id="content-child">
content
</div>
</div>

Bootstrap: How can I change the height of the navbar

This is what I have so far: http://codepen.io/Pabi/pen/bdmgjm
Here is my CSS:
/*---------------------------------------------------
3.1 Topbar
---------------------------------------------------*/
#section-topbar {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 10000;
overflow: visible;
font: normal 16px/24px 'Open Sans', "Helvetica Neue", Helvetica, Arial, sans-serif;
/* border-bottom: 2px solid;
border-color: rgb(232,235,237);*/
}
/*Makes it so when you hover over the icon stays white*/
#section-topbar a {
color: #fff;
}
#section-topbar ul#nav > li {
display: block;
padding: 0;
}
#section-topbar ul#nav a {
display: block;
font: normal 11px/18px "Helvetica Neue", Helvetica, Arial, sans-serif;
text-decoration: none;
padding: 18px 20px 18px 20px;
}
#section-topbar ul#nav .menu-item-left a:hover {
background: #222;
text-decoration: none;
}
#section-topbar ul#nav .active a {
background: #44bbaa;
}
#section-topbar ul#nav .active a:hover {
background: #44bbaa;
}
#section-topbar i {
font-size: 25px;
}
/*Center Brand on NavBar*/
.navbar-brand {
position: absolute;
width: 100%;
left: 0;
text-align: center;
margin: auto;
}
How can I change the height of the navbar to something that is thinner and possible make the dropdown text with a dropdown icon next to it instead of a button.
Thank you very much.
One simple way would be to use the Sass or Less source and change the default value for $navbar-height
The nice thing about this, is that all the other calculations for top and bottom margins or padding of navbar elements will automatically adjust based on the new value. It's a far more maintainable and clean solution than trying to override the compiled styles.
With regard to making the dropdown text instead of a button, see the example from the bootstrap docs of the dropdown in a navbar, http://getbootstrap.com/components/#default-navbar:
<li class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu">
<li>Action</li>
<li>Another action</li>
<li>Something else here</li>
<li role="separator" class="divider"></li>
<li>Separated link</li>
<li role="separator" class="divider"></li>
<li>One more separated link</li>
</ul>
</li>
You should be able to do something very similar inside of your <ul class="nav navbar-nav navbar-right"> element.
You can reduce the height of the topbar with smaller padding around the icons :
#section-topbar ul#nav a {
...
padding: 10px 20px;
}

Centering navigation bar

I am having trouble centering my navigation bar, I have tried display:inline-block and then align center like most posts suggest but it doesn't seem to be working.
HTML:
<!--Navigation-->
<div class="band navigation">
<nav class="container primary">
<div class="sixteen columns">
<ul>
<li>Home</li>
<li>About Us</li>
<li>Projects</li>
<li>Contact Us</li>
</ul>
</div>
</nav>
</div>
CSS:
nav.primary{
display: table;
margin: 0 auto;
}
nav.primary ul, nav.primary ul li {
margin: 0px;
}
nav.primary select {
display: none;
width: 100%;
height: 28px;
margin: 21px 0;
}
nav.primary ul li {
display: inline;
float: left;
position: relative;
}
nav.primary ul li a {
display: inline-block;
line-height: 49px;
padding: 0 14px;
color: white;
text-transform: uppercase;
text-decoration: none;
font-weight: bold;
letter-spacing: 0.08em;
background: ##999999;
}
nav.primary ul li a:hover {
background: #2ecc71;
cursor: pointer;
}
Ok finally got it:
nav.primary ul li {
display: inline;
float: left; <---
position: relative;
Remove the float: left;
Since the navigation is the full width of the containing div, there is no need to mess with floats, the list items will line up with just display: inline;
I tried something else that works... It seems to work better than trying to build in something custom thus far in my experience with Skeleton... Although it produces a bit less pretty markup for the HTML, the rigidity of the final result works for me. Here is my code so that you can see what I did to achieve the desired effect:
<div class="row">
<div class="two columns offset-by-three">
Portfolio
</div>
<div class="two columns">
About
</div>
<div class="two columns">
Contact
</div>
</div>
What you can see here is that the skeleton framework allows for the columns to operate naturally and restack at lower resolutions without any extra code. The only tricky part really is setting up the offset on the left most item.
Have you tried nav.primary ul {text-align: center;}
As well as keeping the left/right margins to auto, this worked for me when I was using the skeleton framework.

Position: Sticky example in JS Fiddle

I am testing the new position:sticky feature but it does not appear to work.
CSS
.slide {
width:300px;
height:400px;
border:1px solid #888;
border-radius:8px;
position:relative;
overflow:auto;
}
.slide > ul {
padding:0;
margin:0;
position:relative;
}
.slide > ul > li {
min-height:20px;
display:block;
padding:10px;
background:#F8F8F8;
box-shadow:inset 0 0 3px #CCC;
list-style:none;
}
.slide > ul > li.title {
min-height:12px;
background:#888;
colour:#FFF;
font-weight:bold;
position:-webkit-sticky;
}
HTML
<div class="slide">
<ul>
<li class="title">Settings</li>
<li>General</li>
<li>Social</li>
<li>Search Engine</li>
</ul>
<ul>
<li class="title">Privacy</li>
<li>Personal</li>
<li>Business</li>
<li>Enigma</li>
</ul>
<ul>
<li class="title">Settings</li>
<li>General</li>
<li>Social</li>
<li>Search Engine</li>
</ul>
<ul>
<li class="title">Privacy</li>
<li>Personal</li>
<li>Business</li>
<li>Enigma</li>
</ul>
</div>
The Fiddle http://jsfiddle.net/78kxU/3/
position: sticky requires you to specify either a top or bottom CSS property in order to determine where/when the sticky element should begin sticking. You should also specify the un-vendor-prefixed value for forwards-compatibility (in this case, it seems to be required, at least on Chrome 30.0.1599.101).
So, in other words, add these two lines to your .slide > ul > li.title style rules:
position: sticky;
top: 0;
Here's the updated fiddle: http://jsfiddle.net/46gpu/

How to prevent absolute position <ul> inside <li> to change its width?

I'm trying to achieve this effect.
Say we have this structure:
<ul id="menu">
<li>Guides
<ul>
<li>Getting Started</li>
<li>Characters</li>
<li>Epics</li>
<li>Road Map</li>
</ul>
</li>
<li>Skills</li>
<li>Equipments</li>
</ul>
and this simplified CSS:
ul#menu {
display:inline-block;
list-style-type:none;
padding:0;
height:30px; /* So the ul#menu's height isn't changed by the ul#menu>li>ul */
overflow:visible; /* So the ul#menu>li>ul is visible on ul#menu>li:hover */
background: #e69646;
box-shadow:0 2px 3px 0 #666;
}
ul#menu>li>ul {
list-style-type:none;
padding:0;
position:absolute;
background:inherit; /* */
box-shadow:inherit;
}
The problem is that having ul#menu>li>ul on absolute positioning makes it lose it's background gradient and shadow. background:inherit and box-shadow:inherit yield this result.
Is there a way to achieve the desired result?
Thank you in advance guys :)
This is the way I would do it - http://jsfiddle.net/bh6L5/3/
<ul id="menu">
<li>Guides
<ul>
<li>Getting Started</li>
<li>Characters</li>
<li>Epics</li>
<li>Road Map</li>
<div id="fake">Guides</div>
</ul>
</li>
<li>Skills</li>
<li>Equipments</li>
</ul>
Then add this to your css
#fake {
position:absolute;
width:45px;
height:31px;
padding:0 10px;
background: #e69646;
z-index:999;
top: -31px;
left:0px;
border-top-left-radius:5px;
border-top-right-radius:5px;
-webkit-border-radius-topleft:5px;
-webkit-border-radius-topright:5px;
-moz-border-radius-topleft:5px;
-moz-border-radius-topright:5px;
}