Cannot remove default Bootstrap padding in navigation bar - html

I have a Bootstrap navigation bar that is more or less customized. The things is, Bootstrap applies padding-left and padding-right to the <a> elements in the navbar. I tried to override the padding-left on the first <a> element in the navbar (the one that says "Collection") but no success. It actually has to look like the first <a> element is starting at the very beginning of the navbar. I added a photo for easier understanding.
Here is the fiddle: http://jsfiddle.net/jxgkrtsd/8/
Code:
<ul class="nav nav-tabs nav-justified" role="tablist">
<div class="bottom-line"></div>
<li>Kolekcija 24<sup> 7</sup></li>
<li>Izdelki</li>
<li>Zgodba</li>
<li>Mediji</li>
<li>Materiali</li>
</ul>
<div class="bottom-line"></div>
CSS:
#import url("http://fonts.googleapis.com/css?family=Exo:400,500&subset=latin,latin-ext");
body {
font-family: 'Exo', sans-serif;
font-weight: 500;
}
.nav > li > a:hover,
.nav > li > a:focus {
background-color: transparent;
border-color: transparent;
}
.nav > li > a {
padding: 10px 5px !important;
margin-right: 0 !important;
color: black;
}
.nav-tabs.nav-justified > li > a {
border-bottom: none;
}
.nav-tabs > li > a:hover {
border-color: none !important;
}
a:hover,
a:focus {
color: black !important;
}
.bottom-line {
height: 1px;
width: 1430px;
background: black;
position: absolute;
}

The problem is not the padding. The problem is that the text is aligned to the center.
Add a text-align: left to your element and things should adjust how you would like them.
This is the code in Bootstrap that is causing the issue
.nav-tabs.nav-justified > li > a {
}
If you alter your jsFiddle you can add it to the following section of CSS:
.nav > li > a {
padding: 10px 5px !important;
margin-right: 0 !important;
color: black;
text-align:left !important;
}
Please note the !important after it. This will override the main call and give the desired effect.
Here is the updated jsFiddle example.

I've needed to do this before. After using <nav class="...."> put the rest of the contents in a new div with class="container-fluid". It should look something like this:
<nav class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container-fluid">
<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 visible-xs" href="{{ HOME_PATH }}/">{{ site.title }}</a>
</div>
...
Then you can use this to get rid of padding for the links in the navbar or for the brand.
nav .container-fluid{
padding-left:0px;
padding-right:0px;
}
To get rid of padding in the links you can use something like this:
.navbar-nav>li>a{
padding-left:0px;
}

I wanted to change the default navbar bootstrap padding. My intention was to change the bottom padding to 4.5rem. Below code worked for me
.navbar{
padding-bottom: 4.5rem !important;
}

The issue is that the a tags in the navigation are displayed as blocks, instead of the inline. You can change it to display as a flexible block by setting the display to flex, then retain the full block area as the link by setting the width to 100%.
Simply add these to your custom CSS for .nav > li > a to look like:
.nav > li > a {
padding: 10px 5px !important;
margin-right: 0 !important;
color: black;
display: flex;
width: 100%;
}
This will retain the top and bottom padding/margins for blocks, the full width of the block as the link, and remove the left/right padding/margin.
Here's a JSFiddle showing it: http://jsfiddle.net/9kzfaypp/

I agree with a few other answers here like #dippas, but to get the text flush to the left, as your picture shows you need to override the anchor padding as well:
.nav-tabs.nav-justified > li > a {
text-align:left;
padding-left:0px !important;
padding-right:0px !important;
}
http://jsfiddle.net/jxgkrtsd/10/

Related

Why does the exact same CSS apply differently when inserted via external stylesheet compared to internal stylesheet?

So I'm revamping my personal website and starting from scratch. I'm starting off with a navbar that's fixed to the bottom. However, when I insert the CSS rules with an internal stylesheet, it works the way I want it to, but when I use those exact same rules with an external stylesheet, the margin does not work properly.
Specifically, this is the problem rule:
.nav li {
margin: -5px;
}
With an internal stylesheet, it acts as intended, covering up unwanted whitespace in between the list items of my navbar (which is a stacked navbar fixed on the bottom).
However, when I put this exact same rule in the external sheet, it does not cover up that whitespace. Some other weird behavior is that if I comment out "margin: -5px;" it changes nothing, but if I comment out all of the rule ".nav li { margin: -5px; } it moves the content of each list item to the left (which is supposed to be centered using "text-align: center" in another rule.
I'm really confused by this odd behavior. Can anyone help me? Thanks.
EDIT: The weird thing is that other than linking bootstrap, jquery, etc. the html and css is pretty much nonexistent. I just put in a navbar and that's about it.
Here's the html in the body:
<div class="container-fluid">
<nav class="navbar navbar-fixed-bottom">
<ul class="nav nav-pills nav-stacked">
<li><a class="about" href="about.html"><div class="navTileContent"><i class="glyphicon glyphicon-user" aria-hidden="true"></i><p>about</p></div></a></li>
<li><a class="portfolio" href="portfolio.html"><div class="navTileContent"><i class="glyphicon glyphicon-briefcase" aria-hidden="true"></i><p>portfolio</p></div></a></li>
<li><a class="art" href="art.html"><div class="navTileContent"><i class="glyphicon glyphicon-edit" aria-hidden="true"></i><p>art</p></div></a></li>
<li><a class="contact" href="contact.html"><div class="navTileContent"><i class="glyphicon glyphicon-envelope" aria- hidden="true"></i><p>contact</p></div></a></li>
</ul>
</nav>
</div>
And here's the only CSS I have:
<style>
.nav li {
margin: -5px;
}
.nav li .navTileContent {
color: #e1e8f4;
text-align: center;
padding: 1%;
}
.nav li .navTileContent p {
padding-left: 20px;
display: inline;
}
.about {
background-color: #6ad8d1;
}
.portfolio {
background-color: #12d132;
}
.art {
background-color: #12466b;
}
.contact {
background-color: #0d336d;
}
</style>
This is meant to be a very simple sort of use case example, so while the styles won't match yours, I hope you see what I am trying to say.
<style>
li {
color: orange;
}
li.active {
color: blue;
}
li.muted {
color: red;
}
</style>
<style>
li {
color: blue;
}
li.active {
color: orange;
}
</style>
<ul>
<li>Notice this is not orange</li>
<li class="active">Notice this is orange</li>
<li class="muted">notice this is red, because nothing has overwritten it's style definition</li>
</ul>

Bootstrap navbar collapse is white/transparent when dropped down

I'm playing with the navbar in Bootstrap, in the hopes of making it a bit smaller than the standard version.
I'm not sure how I did it, but when the size of the screen drops down enough for the toggle menu button to appear, the background is white/transparent instead of the preferred blacker inverse color.
If you have a better way of making the navbar smaller, I'm open to suggestions.
Here's a link to the full code, but will include CSS here also: http://codepen.io/anon/pen/Qbgdbo
.navbar {
height:32px !important;
min-height:32px !important;
margin:0px !important;
}
.navbar-brand {
padding-top:0px !important;
padding-bottom:0px !important;
}
.navbar-nav > li > a {
padding-top:7px !important;
padding-bottom:7px !important;
}
.navbar-header{
height:32px !important;
min-height:32px !important;
margin:0px !important;
}
.navbar-nav {
display: inline-block;
float: none;
}
.navbar-collapse {
text-align: center;
}
.navbar-toggle{
margin:3px;
}
.socialIcons {
max-width:40px;
}
Trevor, If you add the navbar-inverse class to this area of your code it will work as you want it to.
<div class="collapse navbar-inverse navbar-collapse">
<ul class="nav navbar-nav">
<li><a>About Us</a></li>
<li><a>Join Us</a></li>
<li><a>Our Mission</a></li>
<li><a>KickStarter</a></li>
</ul>

Styling Full Hover Effect

I want a css hover effect to last on all sections of a particular list item but it seems like there is added margins on the bottom and left and right of the list item that I can't seem to get rid off. I know this is probably a pretty basic css question but I have a JSFiddle here: http://jsfiddle.net/y2497/
I was using bootstrap to get my base css but I don't think that is affecting it.
My Code is:
#navbar {
padding-bottom: 0px;
margin-bottom: 0px;
}
#nav_container li {
list-style-type: none;
display: inline-block;
margin: 0px 20px 0px 20px;
}
#nav_container li:hover {
background: #333;
}
#nav_container li a {
display: inline-block;
color: #00;
padding: 10px;
}
<nav id="navbar" class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div id="nav_container">
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</div>
</nav>
You are using inline-block on your li tags. What you need to do is apply float:left; and display:block; . Then apply a clearfix to the UL. Inline-block treats elements similar to how text is handled and includes line-height and spaces.

Trying to create a submenu that stretches across entire page

I'm trying to create a submenu that stretches across an entire page on http://jobcreatr.com
The problem is that the submenu is only stretching from the top menu item all the way to the right. I want it to go all the way across. Also, there's some weird padding on the submenu items, which I think is related to the border bottom on hover - which I don't even want on the submenu items.
How do I get the submenu to stretch across the entire page, and also get rid of that weird padding/border-bottom.
Here's the css I have:
.sf-menu.sf-horizontal.sf-shadow ul, .sf-menu.sf-vertical.sf-shadow ul, .sf-menu.sf-navbar.sf-shadow ul ul {
width: 100%;
background-color: #F6F6F6;
background: none;
list-style-type: none;
text-align: center;
margin-top:22px;
overflow: none;
display: none;
}
.sf-menu.sf-horizontal.sf-shadow ul a, .sf-menu.sf-vertical.sf-shadow ul a, .sf-menu.sf-navbar.sf-shadow ul ul a {
background-color: #000/*#F6F6F6*/;
width: 9999px;
}
.sf-menu.sf-style-whiteshadow li {
overflow: visible;
}
.sf-menu.sf-style-whiteshadow li:hover {
border-bottom: 4px solid #000;
}
.sf-menu.sf-style-whiteshadow .sf-depth-2 {
border-bottom: none;
}
Here's the HTML:
<ul id="superfish-2" class="menu sf-menu sf-main-menu sf-horizontal sf-style-whiteshadow sf-total-items-3 sf-parent-items-1 sf-single-items-2 superfish-processed sf-js-enabled sf-shadow">
<li id="menu-1299-2" class="first odd sf-item-1 sf-depth-1 sf-no-children">
<li id="menu-1300-2" class="middle even sf-item-2 sf-depth-1 sf-no-children">
<li id="menu-1301-2" class="last odd sf-item-3 sf-depth-1 sf-total-children-1 sf-parent-children-0 sf-single-children-1 menuparent">
<a class="sf-depth-1 menuparent sf-with-ul" title="" href="http://jobcreatr.com/products">
<ul class="sf-hidden" style="float: none; width: 12em; display: block;">
<li id="menu-1632-2" class="firstandlast odd sf-item-1 sf-depth-2 sf-no-children" style="white-space: normal; width: 9999px; position: absolute; float: left;">
<a class="sf-depth-2" title="" href="http://www.google.com" style="float: none; width: auto;">test</a>
</li>
</ul>
</li>
</ul>
Ideally if you want to make an element take up the whole width you should have it on the same level as your uppermost element which also takes up the whole width (for example body, if your body does not have any width set) and then position this element absolutely with a width of 100%.
However in your case you could use fixed position, try changing your css rules where you have defined width of 9999px to this:
.sf-menu.sf-horizontal.sf-shadow ul a, .sf-menu.sf-vertical.sf-shadow ul a, .sf-menu.sf-navbar.sf-shadow ul ul a {
background-color: #000/*#F6F6F6*/;
width: 100%!important;
position: fixed;
left: 0;
}
The reason why you have to add the !important to your width is because currently the width is being overwritten by javascript responsible for making the menu work. Using !important isn't best practice and if you want to do it properly you should change your javascript so that the width does not get set by it: then you do not need to use the !important rule.
As mentioned in my comment above, change this
.sf-menu.sf-style-whiteshadow li:hover {
border-bottom: 4px solid #000;
}
to this:
.sf-menu.sf-style-whiteshadow > li:hover {
border-bottom: 4px solid #000;
}
to get rid of the bottom border of your submenu item.

Issue with bottom padding/margin with Twitter Bootstrap

So, I'm working on quickly building a website theme (Wordpress) with the aid of Twitter bootstrap, and I'm running into a problem.
I've got a header thrown together, and I've got this weird gap going on inside the "pull-right" section, not sure why:
I'm not sure what the deal is, I want them sitting on the line right at the same height of the text on the left.
Anyway, I've got the following relevant sections of code:
(HTML for header section):
<!-- Header -->
<div class="row header-container">
<div class="col-md-8 col-md-offset-2">
<div class="pull-left">
<h3>CharlesBaker.net</h3>
</div>
<div class="pull-right">
<ul>
<li>Test1</li>
<li>Test2</li>
<li>Test3</li>
</ul>
</div>
</div>
</div>
(CSS for the same section):
.header-container {
padding-top: 50px;
background-color: #c0c0c0;
border-bottom: 5px solid #880000;
}
.header-container h3 {
margin: 0;
padding: 0;
font-family: 'Montserrat', serif;
}
.header-container ul {
margin: 0;
padding: 0;
}
.header-container ul li {
display: inline;
margin: 0;
padding: 0;
}
.header-container a {
padding: 3px;
color: black;
}
.header-container a:hover {
text-decoration: none;
background-color: #880000;
color: white;
}
Not sure what the issue is, unless it's related to the fact that I'm using a tag instead of just styling a <span> or something, but since I removed the padding/margin using CSS, I wouldn't think that would be the problem.
Any help would be great. The idea is that when I hover over the links on the right, that they're enclosed in a scarlet colored box that "extends" from the 5px bottom border.
Thanks in advance!
Are you looking for this?
You need to set your .header-container as display: inline-block to align all elements inside. Therefore, you need to float your pull div elements (float and left).
Just one last change, set the width size of your header: I set 100%, but you can set whatever you like :)
CSS:
.header-container {
padding-top: 50px;
background-color: #c0c0c0;
border-bottom: 5px solid #880000;
width: 100%;
display: inline-block;
}
.pull-left {
float: left;
}
.pull-right {
float: right;
}
There is a particular line-height property for h3 tag with bootstrap.
h1, h2, h3 {
line-height: 40px;//line 760
}
So you will have to add style to negotiate this additional height.
Also another set for your ul as :
ul, ol {
margin: 0 0 10px 25px; //line 812
}
Solution :
Over-ride the ul margin as follows :
.pull-right ul{
margin: 0;
}
Over-ride the line-height for the h3 as follows :
.pull-left h3{
line-height:20px;
}
First one is pretty straight forward and gives you correct alignment straighaway. Second solution will need you to work some more with tweaking the negative-margins for .pull-right.
Debugging URL : http://jsbin.com/oToRixUp/1/edit?html,css,output
Hope this helps.