Even Bootstrap Nav Tabs and Dropdown? - css

I have the following JS Fiddle here as an example:
Original JS Fiddle:
https://jsfiddle.net/dnovdk47/3/
I am trying to get the nav to be justified with even tabs that fill out equal space of the whole navigation menu. My other problem is I need to have the dropdown width and tab width be the same so that the dropdown lines up with the tab when opened. I was able to achieve this by setting the width of the ul dropdown to 100% and using flex
JS Fiddle with Justified Nav:
https://jsfiddle.net/dnovdk47/5/
CSS
.nav {
display: flex;
width: 100%;
}
.nav li {
background-color: #e3e3e3;
flex-grow: 1;
flex-shrink: 1;
flex-basis: 100%;
}
.navbar-inverse .navbar-nav li > a {
height: 45px;
justify-content: center;
align-items: center;
display: flex;
}
.navbar-inverse .navbar-nav li ul {
width: 100%;
}
However, on the Fundamentals tab the dropdown text is larger/too wide and it goes outside of the box.
What I would like is if the tabs could be equal to the width of the dropdown. If it's not doable then maybe just wrap the text to the second line for super long text/elements.
Here is a picture of what I am trying to achieve for all tabs and dropdowns to be even dynamically.

You can add the following css to your dropdown li to break the text into multiple lines.
.dropdown-menu>li>a{
word-wrap: break-word;
white-space: inherit;
text-align: center;
}
JSFiddle: https://jsfiddle.net/dnovdk47/10/

Related

Putting links next to each other - CSS mobile styles

I have my links stacked vertically in my default CSS, but I'm trying to push the nav to the top of the page and set them horizontally in mobile. Can't seem to make it happen.
The site is in WordPress, which makes determining the names of elements difficult.
#sidebaar a, #sidebaar li {
text-align:right;
clear:both;
}
#sidebaar{
width:150px;
text-align, right;
align-content:right;
display:inline-block;
width:100%;
}
In media styles:
#sidebaar a, #sidebaar ul li, #sidebaar ul li a{
display:inline;
clear:none;
} #sidebaar{
width:100%;
}
My site can be viewed here - http://www.ubart320.org/students/mariaroo/gallery/
Your header and navelements contain (in different rules) both width and max-width definitions of 150px for max-width and 160/360px for width which prevent your menu from getting any wider.
You have to define width: 100%; and max-width: none; for both, if necessary, add !important to those values
You have some funky code going on. For some reason you have two menus showing on mobile. However, I set the second menu to display: none; and applied these styles to get an acceptable result (apply this to you mobile styles):
nav{
width: 100%;
max-width: none;
}
ul#menu-menu-2{
display: flex;
flex-direction: row;
justify-content: center;
flex-wrap: wrap;
}
#menu-menu-2 li{
margin: 0 2.5px;
}
See the end result below. It looks like you still have some work to do on the photo grid, but the horizontal nav is acceptable. Let me know if you have any further questions!

html css Vertical list aligning top

I'm trying to create a container with 4 columns, on the top theres an image with some text below it.
But it doesnt align towards the top, but bottom
This is the styling for li
#carousel-navigation li {
list-style: none;
display: inline-block;
width: 23%;
background-color: blue;
}
Here is the fiddle: (the images on the bottom should be on the top instead)
http://jsfiddle.net/G6Jnh/
I'm thinking a table might be easier but it should only be used to display data and not layout they say...
You need to add vertical-align property like following:
#carousel-navigation li {
list-style: none;
display: inline-block;
width: 23%;
background-color: blue;
vertical-align:top; /* add this */
}
Demo
Display the ul as a table and the li as table cells and then use vertical-align as you need to align
#carousel-navigation ul {
display: table;
}
#carousel-navigation li {
display: table-cell;
vertical-align: top;
}
Updated Demo
I added a float: left to your styling for the li and it seems to work.

How to make navbar-links fill out 100% of the width of a page

Here's my struggle. So I've been wondering how I could make the navbar-links fill out 100% of the nav. So that they have an equal amount of spacing and the font-size will decrease if more links were added - this way it will always fill out 100%.
As it is now, I cannot seem to achieve this. I've only got a set padding, but I've tried doing stuff like:
display: block;
float: left;
width: 100%;
but it's giving me all kind of effects that doesn't work at all :S
Anyone able to help me out on this?
Codepen example
Remove width from #main-navigation and add with to #main-navigation li with a value equal to the 100/the_numberof_elements_in_the list. Your css should be:
#main-navigation {
height: 54px;
overflow: hidden;
border-bottom: 1px solid black;
}
#main-navigation ul {
height: 54px;
overflow: hidden;
}
#main-navigation li {
font-size: 1.0em;
text-transform: uppercase;
list-style: none;
float: left;
width: 20%;
}
This way you'll have your nav occupying all the available width, but your font-size will not automatically resize. You'll should change it also in function of the number of elements (similar the way you have to do to the li's width). If your are generating this list dynamically at server side, you could do the same with the css and then calculate the right values for these two attributes. If your are using ajax to populate the list, you could do change the attributes with javascript.
A way of doing this is using display: table on the parent and display:table-cell on the children. I believe it won't work on some versions of IE (of course). Here's an exaple
You can use the nav tag instead and treat it as table. Treat the <ul> tag as table-row and <li> tag as table-cell. Ex:
nav{
display: table;
text-align: center;
width: 100%
}
nav ul{
display: table-row;
}
nav ul li {
display: table-cell;
}
This will stretch the contents of <li> 100%
I learnt it from the following link: http://www.darkstardesign.com/darkstar-blog/2012/11/27/stretching-horizontal-navigation-menus-to-the-full-width-of-a-layout/

Bootstrap Narrow marketing + Justified nav?

I'm trying to use Bootstrap's narrow marketing example with the justified nav example.
However I've hit a bit of a problem trying to create a Dropbox using the justified nav template. Select "Downloads" from the header and the table styled is wrong I believe it's because of display: table-cell; but of course if you remove that it messes up.
I've come up with this
Just change
.navbar .nav li {
display: table-cell;
width: 1%;
float: none;
}
with
.navbar .nav > li {
display: table-cell;
width: 1%;
float: none;
}
and each of the items of the submenu will be a line. This way, you will only apply that three rules to the direct li child of the .nav class and not to the other li elements.
Result: JsFiddle

position:absolute one of display:table-cell elements causes WebKit to render gap

I'm trying to build a horizontal menu with the last item seperated and positioned right, so that a logo finds place between the last and the second last item.
Firefox, Opera (Presto) and even the dirty ones from Redmond (9.0+) render it like I would expect. But WebKit (Chrome and Safari both render it the same) takes some space after the second last item where the last item would stay without position: absolute.
<header>Logo</header>
<nav>
<ul>
<li>Home</li>
<li>Statistics</li>
<li>Data Management</li>
<li>Market Research</li>
<li>Web & Apps</li>
<li>Contact</li>
</ul>
</nav>
I display the list as table and the list items as table-cell because I want the left part of the menu (first to second last item, left to the logo) to have a fixed width while the items take the width they need for their contents. Text could change to anything. Till there, everything is alright. But if I give the last item a display: block; position: absolute, WebKit renders that gap (white in the example).
nav ul
{
display: table;
background: white; /* that's what you see in webkit */
}
nav ul li
{
display: table-cell;
}
nav ul li:last-child
{
display: block; /* "display: none;" works like I would expect */
position: absolute;
}
Here is a Fiddle.
I'm not sure if it is a bug in WebKit, because absolute positioning an element inside a table might not be default behavior. On the other hand, display: none works like I would expect. Shouldn't the space consumption be 0 in both cases?
Does anybody know of a bug in WebKit or has anyone an idea of how to prevent that gap?
Set the penultimate element "Web & Apps" to display block instead of table-cell:
nav ul li:nth-last-child(2)
{
display: block;
}
Display block fiddle
I've pushed this answer on other people, and often got the "flexbox isn't widely supported yet" response. However, here it goes again. The reason that Webkit is misbehaving is that within its implementation of display: table, the DOM is reserving space for the semantically declared cell. The easy way to implement this would be to simply break this element out into its own object, much like you'd done with the logo.
HOWEVER...
if you want to keep these semantically grouped - And why wouldn't you, they're all content, right? - you can always use the flexbox model to overcome this.
Here's a fiddle showing its use.
Here's what we change:
nav ul
{
display: box;
display: -webkit-flex;
flex-direction: row;
-webkit-justify-content: center;
-webkit-align-items: center;
-webkit-flex-direction: row;
background: white; /* that's what you see in webkit */
empty-cells: hide;
table-layout: auto;
}
nav ul li
{
flex: 1 1 auto;
-webkit-flex: 1 1 auto;
}
Now, your items properly cover the background, as it is no longer treating the last li as if it were a true table cell and still within the bounds of the table. Flexbox provides a flexible layout to fill available space. Often people see this as a solution for the "Holy Grail of Layout" problem, but its use expands way beyond just that.
So, if another "Flexbox isn't widely supported enough" response is incoming, I understand. But I'll keep proposing it as an answer on every one of these that I come across, because support is getting better every day.
A little CSS edited, take a look at please, if this what you want, Fiddle
body
{
position: relative;
background: #bbbbbb;
text-align: center;
color: white;
}
header
{
position: absolute;
top: 10px;
left: 630px;
width: 80px;
height: 60px;
line-height: 60px;
background: black;
text-transform: uppercase;
}
nav
{
position: absolute;
top: 20px;
left: 20px;
}
nav ul,
nav li
{
list-style-type: none;
margin: 0;
padding: 0;
}
nav ul
{
width: 200px;
}
nav ul li a
{
display: block;
padding: 1px;
background: #0099ff;
color: white;
text-decoration: none;
}
nav ul li a:hover
{
background: black;
}
nav li{
margin-bottom: 5px;
height: 25px;
line-height:25px;
}
While using absolute, every thing related/relating to that must be absolute in term of pixels.
I have updated fiddle, as your nav + logo .header + .nav:last-child were not totaling proper.
Fiddle link : http://jsfiddle.net/3TUk8/2/
in other case you will have to do that
nav ul
{
display: table;
background: #bbbbbb; /* that's what you see in webkit and same as bg color will hide it :) */
list-style: none;
}
I hope this solve your problem :)

Resources