Vertical Bootstrap Navbar Button Misaligned - html

I'm working on a responsive navigation bar with Bootstrap for my website. I have it mostly figured out, except for one thing. On devices with screen width < ~775px, such that the buttons are stacked vertically instead of horizontally, the first one extends a bit to the left, misaligning it with the rest of the buttons. What is causing this, and how do I fix it?
JSFiddle: https://jsfiddle.net/w10cspvv/
HTML:
<div id="navbar">
<nav class="navbar navbar-default">
<div class="container-fluid">
<ul class="nav nav-pills nav-justified">
<li role="presentation" class="active navbutton">
<img class='squidanim' src='https://www.glowingsquid.com/images/squid.gif' /><span>Home</span>
</li>
<li role='presentation' class='active navbutton'>
<a href='/about.php'><img class='squidanim' src='https://www.glowingsquid.com/images/squid.gif' /><span>About</span></a>
</li>
<li role='presentation' class='active navbutton'>
<a href='/contact.php'><img class='squidanim' src='https://www.glowingsquid.com/images/squid.gif' /><span>Contact</span></a>
</li>
</ul>
</div>
</nav>
</div>
CSS:
body {
background-color: black;
font-size: 16pt;
margin-top: 2em;
}
#navbar {
border: .25em solid #00aeef;
background-color: #00aeef;
border-radius: 25px;
}
.navbar {
margin-bottom: 0em;
}
.navbar-default {
border-radius: 25px;
border-color: #00aeef;
background: #00aeef;
}
.main {
font-family: Ubuntu, Tahoma, Geneva, sans-serif;
margin-left: 6em;
margin-right: 6em;
text-align: center;
}
.nav-pills > li.active > a,
.nav-pills > li.active > a:focus,
.nav-pills > li.active > a:hover {
background-color: #7F00FF;
}
.squidanim {
display: none;
}
.navbutton:hover a > .squidanim {
display: block;
height: 50px;
position: absolute;
z-index: 100;
}
.navbutton {
padding-left: 2em;
padding-right: 2em;
}
.nav > li > a {
padding-top: 0;
padding-bottom: 0;
}
.nav > li > a > span {
padding-top: 10px;
padding-bottom: 10px;
}
#media (max-width: 978px) {
#navbar {
margin-left: 2em;
margin-right: 2em;
}
.main {
margin-left: 1em;
margin-right: 1em;
}
.navbutton {
padding-left: 0;
padding-right: 0;
}
}

I have fixed this in this JSFiddle: https://jsfiddle.net/xpn779Lr/1/
Which overrides the default bootstrap rule
.nav-pills>li+li {
margin-left: 2px;
}
to
.nav-pills>li+li {
margin-left: 0;
}
FYI, this css rule has high specificity.
The plus sign mean that the style applies only to li's directly following another li.
A plain "li" selector would apply the style to every li in the div with a "navpills" class.
See adjacent selectors on W3.org.

Related

Search form vertically fills navbar

I'm trying to put a search form inline within a navbar like so:
But I end up with a navbar like this:
What I'm trying to do is have the green search bar vertically fill the whole navbar. But when I add more padding, the navbar gets more padding also. How can I do it so that the search bar fills the whole navbar like in the first example?
EDIT
Here is the Bootply with static html: http://www.bootply.com/6UyH4u0NWy#
This might get you headed in the right direction using .form-control to set the height of the input.
/* CSS used here will be applied after bootstrap.css */
/* nav */
.navbar-inverse .navbar-nav li a {
padding-top: 15px;
padding-left: 15px;
}
.navbar.navbar-inverse {
background: white;
border-bottom: solid 1px #979797;
}
.navbar-inverse .nav > li > a {
color: #858585;
font-weight: 500;
font-size: 13.5px;
}
.navbar-inverse .nav > li > a:hover,
.navbar .nav > li > a:focus {
color: black;
-webkit-transition: ease 0.2s;
transition: ease 0.2s;
}
.navbar-inverse .navbar-collapse {
border-top: none;
text-align: center;
#media (max-width: 767px) {
background-color: white;
}
}
.navbar-header h4 {
padding: 5px 0 0 10px;
}
.navbar-nav li .search-box {
height: 100%;
margin-top: none;
background-color: #38A6A6;
border: none;
color: white;
border-radius: 0;
padding-left: 15px;
padding-right: 15px;
padding-bottom: none;
}
.navbar-nav li input.search-query {
height: 100%;
padding-left: 26px;
}
.navbar-nav li form.form-search {
height: 100%;
position: relative;
}
.navbar-nav li form.form-search:before {
height: 100%;
display: block;
width: 14px;
height: 14px;
content: "\e003";
font-family: 'Glyphicons Halflings';
color: white;
background-position: -48px 0;
position: absolute;
top: 16px;
left: 8px;
z-index: 1000;
}
.navbar-nav li .form-control {
height: 50px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar navbar-fixed-top navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<h4>Brand</h4>
</div>
<ul class="nav navbar-nav navbar-right">
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
<li>
<form class="form-search form-inline">
<input type="text" class="search-box form-control" placeholder="Recipient's username" aria-describedby="basic-addon2" />
</form>
</li>
</ul>
</div>
</nav>
How about setting the height of .form-search to 100% ? The reason it has this current height is because its scale depends on its content (height:auto by default).
Also notice you got syntax errors in your html (closing li tag before closing form tag).

nav bar will not change colour. Corrected html and css markup. No effect

Hi I have a navbar on my website. But the font is orange and the hover...white.
I want the font white and the background purple. I cannot seem to override the bootstrap.css even though my style.css is below the bootstrap.css. I've even tried filling in every colour in .nav bar with #000000; to see what would happen and commenting out...no effect!
The only thing that changes is the margin. Originally the issue was my html markup..but I've corrected it..however the issue still persists. The font is orange but I have no idea how it's orange as I've looked through both the style.css and bootstrap.css.
Help would be greatly appreciated. Thank you
index.html
<!-- HEADER AND NAVBAR -->
<header>
<div class="wrap">
<!-- logo -->
<ng-controller="demoCtrl">
<ul class="nav nav-pills pull-right">
<li ng-class="{active: isState('home') }">
<a ui-sref="home">HOME</a>
</li>
<li ng-class="{active: isState('form') }">
<a ui-sref="form">CANDIDATES</a>
</li>
<li ng-class="{active: isState('clients') }">
<a ui-sref="clients">CLIENTS</a>
</li>
<li ng-class="{active: isState('aboutus') }">
<a ui-sref="aboutus">ABOUT US</a>
</li>
<li ng-class="{active: isState('training') }">
<a ui-sref="training">TRAINING</a>
</li>
</ul>
<h3 class="text-muted"> </h3>
<br>
</div>
</header>
style.css
/* general settings */
html {
min-height: 100%;
overflow-x: hidden;
overflow-y: scroll;
position: relative;
width: 100%;
background-color: #000;
}
body {
background-color: 000;
font-family: "Verdana", sans-serif;
color: #c4c4c4;
font-size: 16.0px;
line-height: 1.19em;
color: #000;
font-weight: 100;
margin: 0px;
min-height: 100%;
width: 100%;
}
* {
font-family: Verdana;
}
a {
text-decoration: none;
}
a img {
border: none;
}
h1 {
font-size: 3.5em;
font-weight: 100;
font-family: "Verdana", sans-serif;
color: #c4c4c4;
font-size: 16.0px;
line-height: 1.19em;
}
p {
font-size: 1.5em;
}
/*input,textarea {
-webkit-appearance:none;
background-color:#f7f7f7;
border:none;
border-radius:3px;
font-size:1em;
font-weight:100;
}
*/
header {
height: 110px;
}
header .wrap {
height: 100%;
}
header .logo {
margin-top: 10px;
width: 300px;
height: 100px;
}
header nav {
float: right;
margin-top: 17px;
}
header .nav ul {
margin: 1em 0;
padding: 0;
}
header nav ul li {
display: block;
float: left;
margin-right: 20px;
}
header nav ul li a {
border-radius: px;
color: #000000;
font-size: 1.4em;
font-weight: 400;
padding: 10px 27px;
text-decoration: none;
background: ##1bbeb7;
display: block;
font-family: Arial, Helvetica, sans-serif;
}
}
header nav ul li a.active {
background-color: #000000;
color: #000000;
}
header nav ul li a.active:hover {
background: #000000;
color: #000000;
}
header nav ul li a:hover,
header nav ul li a.activeSmall {
color: #000000;
background: #000000;
}
I'm not going throw all your code since it's pretty unclear but to override those styles on basic bootstrap you just need this:
.nav {
background: purple;
color: orange;
}
.nav>li>a {
color: orange;
}
.nav-pills>li>a:hover {
color: white;
background: transparent;
cursor: pointer;
}
BootplyDemo
You have a few bad selectors:
header nav ul li a.active:hover {
There is no nav tag in your code! You do have ul.nav but no nav as its parent. So the line above should be:
header ul.nav li a.active:hover {
Make sure you do so with the others as well.
If the fix above doesn't work: it could be that you have some repeated rules for the nav (I see a lot of repeated rules in your code) with higher specificity, so use Dev Tools to see which rules are applied in the end, then find where they are set and modify them (or override them in your file if they are default rules) using their original specificity.
Here is a specificity calculator to help you understand which rules have higher priority than the others: http://specificity.keegan.st/

Cannot correctly position horizontal list inline with <a>'s?

So basically I'm doing a layout with a large image feature, that can move from one picture to another using arrows beneath. Honestly it's quite a lot like the front page of flipboard.com, in regard to the picture feature.
.feature-nav {
width: 234px;
margin: auto;
}
.prev-arrow {
display: inline;
font-size: 30px;
color: #B6B6B6;
}
.prev-arrow:hover {
color: #428bca;
}
.feature-nav ul {
display: inline;
}
.feature-nav li {
display: inline;
}
.nav-dot a {
font-size: 30px;
color: #B6B6B6;
}
.next-arrow {
display: inline;
font-size: 30px;
color: #B6B6B6;
}
.next-arrow:hover {
color: #428bca;
}
<div class="feature-nav">
<
<ul>
<li class="nav-dot">•</li>
<li class="nav-dot">•</li>
<li class="nav-dot">•</li>
</ul>
>
</div>
The output:
Does anyone know why the dots and right arrow are so far shifted from the left arrow? I've tried adjusting padding, margins, the "left: " property, and all of them work accept the make the left arrow not select properly, it only recognizes that you're hovering over it if you hover over a very small certain area. Right now, with the shown code, it doesn't do that, but the positioning is off. Does anyone have any ideas?
Because unordered lists have a default padding that you can get rid of by adding padding:0 to your .feature-nav ul rules:
.feature-nav {
width: 234px;
margin: auto;
}
.prev-arrow {
display: inline;
font-size: 30px;
color: #B6B6B6;
}
.prev-arrow:hover {
color: #428bca;
}
.feature-nav ul {
display: inline;
padding:0;
}
.feature-nav li {
display: inline;
}
.nav-dot a {
font-size: 30px;
color: #B6B6B6;
}
.next-arrow {
display: inline;
font-size: 30px;
color: #B6B6B6;
}
.next-arrow:hover {
color: #428bca;
}
<div class="feature-nav">
<
<ul>
<li class="nav-dot">•</li>
<li class="nav-dot">•</li>
<li class="nav-dot">•</li>
</ul>
>
</div>
Try display: inline-block for the arrows and list items, and give them padding for a larger "hit" area for when hovering. You can also set a right or left margin for the arrows or list items to separate them a bit as well.
As for why they're off-center, remove padding from the ul element.
As for the
.feature-nav {
width: 234px;
margin: auto;
}
.prev-arrow {
display: inline-block;
padding 10px;
margin-right: 20px;
font-size: 30px;
color: #B6B6B6;
}
.prev-arrow:hover {
color: #428bca;
}
.feature-nav ul {
display: inline;
padding: 0;
}
.feature-nav li {
display: inline-block;
margin: 0 5px;
}
.nav-dot a {
font-size: 30px;
color: #B6B6B6;
}
.next-arrow {
display: inline-block;
padding 10px;
margin-left: 20px;
font-size: 30px;
color: #B6B6B6;
}
.next-arrow:hover {
color: #428bca;
}
<div class="feature-nav">
<
<ul>
<li class="nav-dot">•</li>
<li class="nav-dot">•</li>
<li class="nav-dot">•</li>
</ul>
>
</div>

Cannot properly centre nav bar (uses col-md-3) bootstrap css and html

so basically I've got this code: HTML and CSS below, using bootstrap as well, and for some reason, it's not centred. It used to be, but at some point it wasn't anymore, now it pulls to the left. See image below. Any ideas?
<div class="row" id="nav-bar">
<div class="col-md-9">
<ul>
<li class="col-md-3 nav-btn" id="home">Home</li>
<li class="col-md-3 nav-btn" id="about">About</li>
<li class="col-md-3 nav-btn dropdown-toggle" id="games">
Games & Apps ▼
<div class="dropdown">
<ul>
<li>Games & Apps ▼</li>
<li id="first">Space Rodeo</li>
<li id="spaced">Boodya's Carpet Ride</li>
<li id="spaced">Ultimate Points Counter</li>
</ul>
</div>
</li>
<li class="col-md-3 nav-btn" id="blog">Blog</li>
</ul>
</div>
</div>
#nav-bar {
margin: 0px 0px 10px 0px;
height: 60px;
}
#nav-bar ul {
margin-top: 20px;
}
.col-md-3 a {
padding: 15px 40px 15px 40px;
font-size: 20px;
text-decoration: none;
text-align: center;
color: #B6B6B6;
}
#nav-bar a:hover {
color: #428bca;
}
.col-md-3 {
display: inline;
}
.col-md-9 {
float: none;
margin: auto;
left: 0;
right: 0;
}
.dropdown {
padding: 0;
margin-top: -48px;
position: absolute;
z-index: 10;
background-color: #ffffff;
box-shadow: -5px -5px 20px;
border-radius: 5px;
height: 210px;
width: 275px;
}
.dropdown ul {
padding: 0;
margin-top: 0;
}
.dropdown li {
list-style: none;
padding: 0;
width: 310px;
}
#games2 {
color: #428bca;
}
#spaced {
margin-top: 10px;
}
#first {
padding-top: 20px;
border-top: 1px solid black;
margin-top: 22px;
}
Showing result of code, the navbar is off centre
http://i.stack.imgur.com/smtTP.png
Your list items are display: inline which means they'll follow the alignment rules of text. Since you set no text-align, it defaults to the left. You can fix that by adding text-align: center to your ul so the contents will be centered.
Now the insides of the dropdown will also inherit that, you can reset that by setting text-align: left back on the dropdown ul again.
Also reset the left padding that ul has by default.
#nav-bar ul {
padding-left: 0;
text-align: center;
}
#nav-bar .dropdown ul {
text-align: left;
}
Works in this jsFiddle

My Horizontal Navigation Bar Won't Display Horizontally, Why?

My navbar refuses to display horizontally. I have put all li elements floating to the left and added the display:inline-block element to the individual blocks and to the list elements and to the list itself and tried every combination. I finally got the list to how I like it and now the only thing keeping this list from being perfect is that it is not displaying horizontally. WHY???
<head>
<title>Troop 25 Homepage</title>
<style>
.navbar {
float: top;
width: 182.8px;
height: 30px;
display: inline-block;
}
li {
float: left;
display: inline-block;
}
.nav {
list-style-type: none;
margin: 0;
padding: 0;
position: relative;
display: inline-block;
}
a:link, a:visited {
display: inline-block;
width: 182.8px;
line-height: 30px;
padding-top: 13px;
padding-right: 5px;
padding-bottom: 4px;
padding-left: 5px;
text-decoration: none;
text-align: center;
background-color: #006b00;
color: white;
font-weight: bold;
float: left;
}
a:hover, a:active {
background-color: #C0C0C0;
}
a:active {
color: grey;
}
.nav_bar_text {
font-size: 17px;
}
.Mackin_text {
font-size: 17px;
vertical-align: text-center;
}
h1 {
text-decoration: underline;
color: #006b00;
}
p {
font-size: 30px;
}
</style>
</head>
Here is my HTML for my list.
<div class="navbar">
<ul class="nav">
<li><a class="nav_bar_text" href=#Home>Home</li></a>
<li><a class="nav_bar_text" href="#Resources">Resources</li></a>
<li><a class="nav_bar_text" href="#Calendar">Calendar</li></a>
<li><a class="nav_bar_text" href="#Year Plan">Year Plan</li></a>
<li><a class="nav_bar_text" href="#Gallery">Gallery</li></a>
<li><a class="nav_bar_text" href="#Videos">Videos</li></a>
<li><a class="Mackin_text" href="#Mackin Society">Mackin Society</li></a>
</ul>
</div>
Change your .navbar width to be 100%
.navbar
{
float:top;
width:100%;
height:30px;
display:inline-block;
}
Try this