I have a super simple site, here that uses a sticky nav bar. The list items are a couple of spots off to the left and I can't figure out why. I've tinkered with all the margins and padding I can think of, but it won't budge. I should also point out that I'm using Bootstrap.
Here is my HTML:
<div id="nav-wrapper">
<div id="nav" class="navbar navbar-inverse affix-top" data-spy="affix">
<div class="navbar-inner" data-spy="affix-top">
<div class="container">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<!-- Everything you want hidden at 940px or less, place within here -->
<div class="nav-collapse collapse">
<ul class="nav">
<li>Home</li>
<li>Services</li>
<li>Contact</li>
</ul><!--/.nav-->
</div><!--/.nav-collapse collapse pull-right-->
</div><!--/.container-->
</div><!--/.navbar-inner-->
</div><!--/#nav /.navbar navbar-inverse-->
</div><!--/#nav-wrapper-->
And here is my CSS that relates to my navigation:
.navbar {
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
padding:0;
z-index:999;
margin-bottom:0;
}
.navbar.navbar-inverse .navbar-inner {
background: #390 url(../img/green-bg.png) repeat;
border:none;
-webkit-border-radius: 0;
-moz-border-radius: 0;
border-radius: 0;
margin-bottom:0;
}
.navbar .nav, .navbar .nav > li {
float:none;
display:inline-block;
*display:inline; /* ie7 fix */
*zoom:1; /* hasLayout ie7 trigger */
vertical-align: top;
padding:0 2em;
margin:0;
}
.navbar-inner {
text-align:center;
margin-bottom:0;
}
.navbar-inner ul.nav li {
text-align: center;
}
.navbar .nav > li a{
color:white;
background:rgba(0,0,0,0.2);
text-shadow:none;
font-size:1.5em;
font-family: marvel, serif;
padding:.5em 1em;
margin:.5em 1em;
}
.navbar .nav > .active a:hover, .navbar .nav > li a:hover, .navbar .nav > .active a {
color:white;
background: #390 url(../img/green-bg.png) repeat;
text-shadow:none;
font-size:1.5em;
font-family: marvel, serif;
padding:.5em 1em;
margin:.5em 1em;
-webkit-box-shadow: inset 0 0 10px #000;
-moz-box-shadow: inset 0 0 10px #000;
box-shadow: inset 0 0 10px #000;
}
.navbar .nav > li {
padding:1em;
margin:0;
}
#nav.affix, #nav.affix-bottom {
position: fixed;
top: 0;
width: 100%
}
#nav {
position:relative;
z-index:999;
-webkit-perspective: 1000; -webkit-backface-visibility: hidden;
}
I know it's a minor detail, but I've been trying to fix it for days now and can't figure out why it's being a pain.
Thanks for your help,
Brian
You have a right margin of 10px on the .navbar .nav(bootstrap.min.css:9) which pushes it a bit to the left.
Change this:
.navbar .nav {
display:block;
float:left;
left:0;
margin:0 10px 0 0;
position:relative;
}
to this:
.navbar .nav {
display:block;
float:left;
left:0;
margin:0;
position:relative;
}
The good news, is here is how to center the list items:
Add a class called ".center" like so:
<div class="navbar navbar-fixed-top center">
<div class="navbar-inner">
....
</div>
</div>
And then use this CSS:
.center.navbar .nav,
.center.navbar .nav > li {
float:none;
display:inline-block;
*display:inline; /* ie7 fix */
*zoom:1; /* hasLayout ie7 trigger */
vertical-align: top;
}
.center .navbar-inner {
text-align:center;
}
To realign the drop down menus, use this:
.center .dropdown-menu {
text-align: left;
}
This was taken from a previous answer.
Now, the bad news, is that solution also centers the menu items on the mobile-menu drop down for tablet and mobile viewports. I literally just posted a question on there ten minutes ago here:
How to Override/Undo CSS Class Attributes for Twitter Bootstrap
If you find a solution, please let me know because we are both asking the same question!
Related
My website has a 3 item in nav menu, I've turned off the responsive menu toggle, and want it to drop below the logo in tablet and mobile. However, I'm unable to do that. I just want navbar to drop a line and retain the same look.
Screengrab
Full width vs mobile
I've placed block on both .srt-menu classes in both the full size and 480 screens, but nothing works. Also declared a width for each menu item, or removing all block displays and using float.
Any help would be appreciated.
Here's the HTML code:
<header class="wrapper clearfix">
<div id="banner">
<div id="logo"><img src="images/header.png" alt="logo"></div>
</div>
<!-- main navigation -->
<nav id="topnav" role="navigation">
<ul class="srt-menu" id="menu-main-navigation">
<li class="about">About</li>
<li class="gallery">Gallery</li>
<li class="contact">Contact</li>
</ul>
</nav><!-- end main navigation -->
</header>
#menu-main-navigation{
display:block;
}
.srt-menu, .srt-menu * {
margin: 0;
padding: 0;
list-style: none;
}
.srt-menu ul {
position: absolute;
display:none;
width: 12em; /* left offset of submenus need to match (see below)
*/
}
.srt-menu ul li {
width: 20%;
}
.srt-menu li:hover {
visibility: inherit; /* fixes IE7 'sticky bug' */
}
.srt-menu li {
float: left;
position: relative;
margin-left:1px;
max-width: 100px;
}
.srt-menu li li {
margin-left:0px;
}
.srt-menu a {
display: block;
position: relative;
}
#topnav, .srt-menu {
float:right;
margin: 1.2em 0 0 0;
}
.srt-menu a {
text-decoration:none;
color: #000000;
}
.srt-menu li a {
background:#fff;
margin:0;
padding:0px 25px;
height:45px;
max-width: 100px;
}
.srt-menu a, .srt-menu a:visited { /* visited pseudo selector so IE6 applies text colour*/
color: #000000;
}
/*LARGER MOBILE DEVICES
This is for mobile devices with a bit larger screens.*/
#media only screen and (min-width: 480px) {
#banner{
float:left;
text-align:left;
margin-bottom:20px;/*this depends on the height of the logo*/
}
.topnav {
float:left;
margin: .2em;
}
.srt-menu, ul.srt-menu {
display: block !important;
}
}
Fixed! I guess I needed to write out the problem.
I made a navbar with different colored buttons and hover effects, but I didn't specify 'inline-block' for them. In full-width, the navbar inherited margins and widths from the parent div.
Basically, change a block to inline-block, tweaked some padding and margins.
.srt-menu li.about, .srt-menu li.gallery, .srt-menu li.contact {
display:inline-block;
margin:1px 0;
padding:10px;
text-decoration:none;
font-size: 1.4em;
}
I tried to create a navigation bar which should fit inside a div id called #page_wrap
itd width is 980px when i tried with firebug i am seeing that #nav selection is bigger than #page_wrap.Why this is happening.
my intention is the nav bar should not go outside the #page_wrap
Here is the Code
HTML
<div id="page_wrap">
<ul id="nav">
<li>Menu1</li>
<li>Menu2</li>
<li>Menu3</li>
<li>Menu4</li>
<li>Menu5</li>
<li>Menu6</li>
<li>Menu7</li>
<li>Menu8</li>
<li>Menu9</li>
</ul> <!-- END Navigation Bar-->
<div id="content">
</div>
</div> <!-- END page_wrap -->
CSS
ul#nav {
list-style: none;
width:980px;
height:35px;
background:#000000;
}
ul#nav li a {
float:left;
color:white;
text-decoration: none;
width:105px;
line-height: 35px;
border-right: 2px solid #979797;
text-align: center;
}
ul#nav li a:hover {
background: #979797;
}
#page_wrap {
margin:0 auto;
width:980px;
}
See the image it has empty spaces in start and end. Why there are empty spaces in the start and End. How to avoid those things. I believe this is what causing a problem of bigger than its parent.
How to Remove Start and End emtpy Spaces and how to place #nav inside #page_wrap exactly which means it should not go out from #page_wrap. Any Help?
Check this JSFIDDLE
Remove default padding for the UL.
ul#nav{padding:0;}
LIke this
demo
css
*{
margin:0;
padding:0;
}
ul#nav {
list-style: none;
width:980px;
height:35px;
background:#000000;
margin:0 auto;
padding:0;
}
ul#nav li a {
float:left;
color:white;
text-decoration: none;
width:105px;
line-height: 35px;
border-right: 2px solid #979797;
text-align: center;
}
ul#nav li a:hover {
background: #979797;
}
#page_wrap {
margin:0 auto;
width:980px;
}
Use this at the start of your css
* {
padding: 0;
}
I have been having a dreadful time trying to center my navbar li in the center of my navbar using Bootstrap. I have tried using info from similar questions such as this one, this one, and this one. My navigation doesn't use pills or tabs, but I was hoping I could edit my code accordingly. My site uses a sticky nav, which is probably the most complicated thing on my page. I've create a JSFiddle using the same code I've uploaded, but for some reason the JSFiddle code properly aligns everything, whereas on my page, all the links are offset to the right 10 or so pixels. I've tried setting all my margins and padding to 0 as well, still no luck.
Can somebody please help me, this is annoying the crap out of me and I'm about to throw my computer off the roof! If you can solve my problem I'll bake you some cookies.
Thanks,
Brian
P.S. Sorry for all the links :-/
Here's my JSFiddle
Here's my HTML:
<div id="nav-wrapper">
<div id="nav" class="navbar navbar-inverse affix-top center" data-spy="affix">
<div class="navbar-inner pull-center" data-spy="affix-top">
<div class="container">
<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<!-- Everything you want hidden at 940px or less, place within here -->
<div class="nav-collapse collapse">
<ul class="nav">
<li>Home</li>
<li>Services</li>
<li>Contact</li>
</ul><!--/.nav-->
</div><!--/.nav-collapse collapse pull-right-->
</div><!--/.container-->
</div><!--/.navbar-inner-->
</div><!--/#nav /.navbar navbar-inverse-->
</div><!--/#nav-wrapper-->
Here's my mess of a CSS:
.navbar {
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
padding:0;
z-index:999;
margin-bottom:0;
}
.navbar.navbar-inverse .navbar-inner {
background: #390 url(../img/green-bg.png) repeat;
border:none;
-webkit-border-radius: 0;
-moz-border-radius: 0;
border-radius: 0;
margin-bottom:0;
}
.navbar .nav, .navbar .nav > li {
display:inline-block;
*display:inline; /* ie7 fix */
*zoom:1; /* hasLayout ie7 trigger */
vertical-align: top;
padding:0 10px;
margin:0 auto;
}
.navbar .nav > li a {
color:white;
background:rgba(0, 0, 0, 0.2);
text-shadow:none;
font-size:1.5em;
font-family: marvel, serif;
padding:.5em 1em;
margin:.5em 1em;
min-width:90px;
}
.navbar .nav > .active a:hover, .navbar .nav > li a:hover, .navbar .nav > .active a {
color:#FFF;
background: #390 url(../img/green-bg.png) repeat;
text-shadow:none;
font-size:1.5em;
font-family: marvel, serif;
padding:.5em 1em;
margin:.5em 1em;
-webkit-box-shadow: inset 0 0 10px #000;
-moz-box-shadow: inset 0 0 10px #000;
box-shadow: inset 0 0 10px #000;
}
.navbar .nav > li {
padding:1em;
margin:0;
width:10em;
}
#nav.affix, #nav.affix-bottom {
position: fixed;
top: 0;
width: 100%;
-webkit-box-shadow: 0px 2px 4px #000;
-moz-box-shadow: 0px 2px 4px #000;
box-shadow: 0px 2px 4px #000;
}
#nav {
position:relative;
z-index:999;
-webkit-perspective: 1000;
-webkit-backface-visibility: hidden;
}
.center.navbar .nav, .center.navbar .nav > li {
float:none;
display:inline-block;
*display:inline; /* ie7 fix */
*zoom:1; /* hasLayout ie7 trigger */
vertical-align: top;
}
.center .navbar-inner {
text-align:center;
}
.navbar .nav > .active a:hover, .navbar .nav > li a:hover, .navbar .nav > .active a and .navbar .nav > li a both have a rule of margin: 0.5em 1em;. Change it to margin: 0.5em 0;.
.navbar .nav, .navbar .nav > li has a rule of float: center;. Remove it.
Add this rule:
.navbar .nav {
float: none;
}
Try changing
.navbar .nav, .navbar .nav > li {
float:center;
...
to
.navbar .nav, .navbar .nav > li {
text-align:center;
...
As far as I know there is no such thing as float center. Only left, right, none, and inherit.
Try adding this class to ul after nav
.nav-center {
float: none;
}
this will override the float: left which comes from bootstrap.css.
Here is the page I am working on: http://www.sackling.com/new_arrivals.php
It seems to look good in all browsers except ie7.
I can't seem to figure out a way to make it work properly in all browsers it must be something with the way I am trying to stack my divs..
This is the important css:
#menuwrap {
width:940px;
height:84px;
position:relative;
z-index:99999;
}
.top_menu_container {height:60px;}
.menu_holder {width:980px; z-index:9999;}
.menu_right_bottom {width:220px; }
/*Menu Start */
.navtest{list-style:none;}
.navtest ul li {
display: block;
position: relative;
float: left;
cursor:pointer;
z-index:9999;
position:static;
}
.navtest ul li a {
text-transform:uppercase;
font-size: 11px;
display: block;
text-decoration: none;
color: #3F3F41;
padding: 5px 21px 5px 20px;
margin-left: 1px;
white-space: nowrap;
z-index:9999;
font-weight:normal;
text-shadow: 0px 1px 1px rgba(0,0,0,0.3);
}
.navtest ul li ul { opacity:0.80; width:141px; display:none; }
.navtest ul li:hover ul{ display: block; position: absolute; z-index:9999; }
.navtest ul li:hover li { float: none; z-index:9999;}
.navtest ul li:hover a { background: #fff; z-index:9999; color: #999; } /* main menu rollover color change */
.navtest ul li a:active {text-shadow: 0px 0px 0px rgba(0,0,0,0);} /*main menu click */
.navtest ul li:hover li a:hover { background: #c0c1c0; z-index:9999;} /*hover over background of dropdown */
.navtest ul li:hover ul li a {color:#000;} /* color of drop down on main rollover */
.top_buttons .navtest ul li a { font-size: 10px; } /* top menu row font */
*{margin:0; padding:0;}
body { margin: 0 auto; font-size: 13px; color: #333333; }
html, body { color: #000000; margin:0; padding:0; height:100%; font-family:"Lucida Grande","Lucida Sans Unicode","Lucida Sans","DejaVu Sans","Bitstream Vera Sans","Liberation Sans",Verdana,"Verdana Ref",sans-serif; }
.header_space { height: 15px;; clear: both; width:940px; margin:0 auto;}
.wrapper {width:940px; margin-left:20px; margin-right:20px; background:#fff; overflow:hidden; margin:0 auto; }
.container {min-height:100%; height: auto !important; height:100%; margin: 0 auto -25px; width:980px; background:URL(images/bg_sides.jpg) repeat-y #f4f4f4; }
.contentContainer {width:980px;}
.banner_listings {margin:0; padding:0; height:293px; width:940px;}
.category_product_style {padding:10px 0px 0px 13px;}
#account_content {background: url(/images/account_nav_bg.png) repeat-x left top; margin-top:35px;}
/* =Account nav */
#account_nav {margin-bottom:55px; margin-top:35px; background: url(/images/account_nav_bg.png) repeat-x left top; float: left; width: 180px;}
#account_nav h2, .table_legend h2, #account_credits h2 { font-size:125%;}
/***********header stuff ************************/
.styled-select {padding-top:6px;}
#searchwrapper {
width:246px; /*follow your image's size*/
height:26px;/*follow your image's size*/
background:#ccc;
background-repeat:no-repeat; /*important*/
padding:0px;
margin:0px;
position:relative; /*important*/
}
#searchwrapper form { display:inline ; }
.searchbox {
border:none; /*important*/
background-color:transparent; /*important*/
background-image:url(images/blank_search.gif);
position:absolute; /*important*/
top:7px;
left:9px;
width:225px;
height:14px;
color:#fff;
font-size:14px;
margin:0px;
}
.searchbox_submit {
border:none; /*important*/ /*important*/
background: url(images/searcharrow.jpg) no-repeat;
position:absolute; /*important*/
top:3px;
left:225px;
width:15px;
height:20px;
margin:0px;
}
Try removing all whitespaces within the ul's in the menu - IE7 renders 2 spaces just above the first menu.
EDIT: i think it's the redundant ul/li - try changing ul class"navtest" to div class="navtest", and remove the li in the left & right menu...
I believe your issue is with the ul#nav-test element. For some reason you have a ul nested within an li within a ul. Was this a mistake or have you done this for a reason?
See line 92 :
<ul class="navtest" >
<li>
<ul>
<li>Fall Catalog</li>
<li>Contact us</li>
</ul>
</li>
</ul>
Remove the additional ul and this will probably resolve your issue as IE7 is assigning a 16px offset from the top of the second ul.
So your HTML becomes:
<ul class="navtest" >
<li>Fall Catalog</li>
<li>Contact us</li>
</ul>
So i have an issue with a CSS dropdown menu being displayed wrong in IE. In other browsers it works like it should.
<body>
<div id="container">
<header>
<div id="hlogo">
title
</div>
<nav id="hmenu">
<ul>
<li>
menu1
</li>
<li>
menu2
<div id="items" class="hiddenMenu">
submenu1
submenu2
submenu3
submenu4
</div>
</li>
<li>
menu3
</li>
<li>
menu4
</li>
</ul>
</nav>
</header>
<section id="container-body">
<div id="content">
</div>
</section>
</div>
So this is my complete HTML. It has a layout provided by the following css.
/* layout styles */
*{margin:0;padding:0;font-family:Arial;}
header{overflow:hidden;}
body{background-color:#cc3333;}
a {display: inline-block;font-weight: bold;text-decoration:none;}
footer {
display:block;
position:relative;
width:100%;
}
footer > #disclamer {
margin-left: auto;
margin-right: auto;
width: 200px;
padding-bottom:5px;
font-size:small;
font-weight: bold;
}
#container{
background-color:#ffffff;
margin:auto;
min-width:756px;
width:60%;
overflow:hidden;
border:solid 2px #666666;
margin-top:10px;
margin-bottom:10px;
box-shadow:0 1px 3px rgba(0,0,0,0.6);
}
#hlogo {float:left;height:105px;width:181px;padding:10px;}
#hlogo a{background-position: 0px 0px;float:left;display:inline;height:105px;text-indent:-999999em;width:181px;}
#hlogo a{background-image:url('../images/logo.png');background-repeat:no-repeat;overflow:hidden;}
#hmenu{margin-top:45px;padding:10px;}
nav {
list-style:none;
display:inline;
float:right;
}
nav ul{
list-style: none;
text-align:center;
background-color:#666666;
float:left;
}
nav ul li {
width:128px;
float:left;
display:inline-block;
}
nav ul li:hover{
background-color:#cc3333;
cursor:pointer;
}
nav ul li a {
color:#ffffff;
padding:10px;
}
nav ul {
background: #222 url('../images/overlay.png') repeat-x;
color: #fff;
text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
cursor: pointer
}
section {margin:10px;}
#container > header {display:block;}
#container-body {
background-color:#ececec;
height:600px;
display:block;
overflow:auto;
}
#container-body > #content {
margin: 10px;
height:95%;
position:relative;
}
.hiddenMenu
{
position:absolute;
z-index: 150;
background: #222 url('../images/overlay.png') repeat-x;
color: #fff;
text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
cursor: pointer;
width: inherit;
}
.hiddenMenu > a
{
position:relative;
text-align: left;
clear:both;
font-size:0.75em;
}
nav li .hiddenMenu > a
{
display:none;
}
/*nav li:hover .hiddenMenu > a
{
display:block;
}*/
nav li .hiddenMenu > a:hover
{
background-color:#cc3333;
cursor:pointer;
border: 1px black solid;
}
This is the full CSS.
This is the CSS i use. Now in firefox it works as it should. The menu is show when i hover the menu2 item. On IE it shows the first submenu item (submenu1) and then it is cleared so i can't even click it.
I can't see what i'm doing wrong so if you can help me i would appreciate it. Thanks!
edit: added code.
The header tag has an overflow:hidden attribute; if i set that to visible it will show the complete menu but will mess up my layout completely. Is there a way around it or am i doing something wrong?
Also, i have a jquery script to set the display on the menu to none/block accordingly but in IE if i hover on the submenu items the menu will still be hidden. Why does this happen?
In my experience IE gets a bit buggy when you don't set the positions of an absolute positioned object. Like top: 0 and left: 0 for instance.
Edit:
Also, parent of the absolute positioned object should have position: relative; if the position should be using the parent dimensions as a starting point.
Edit2:
li:hover doesn't work in IE6 I think. Can't remember about IE7. One of them will only accept a:hover, and browsers below maybe none of them. jQuery solves things like that though.
Edit3:
I don't know what the nav stuff is, I haven't jumped to HTML5 so I don't know if it's relevant later. But anyway I've made something that works of your code.
Script (jquery):
$(document).ready(function () {
$('#hmenu ul li').hover(function () {
$(this).children('div').css('display', 'block');
},
function () {
$(this).children('div').css('display', 'none');
});
});
CSS:
#hmenu {
list-style: none;
display: inline;
float: right;
}
#hmenu ul {
list-style: none;
text-align: center;
background-color: #666666;
float: left;
}
#hmenu ul li {
width: 128px;
float: left;
position: relative;
display: inline-block;
}
#hmenu ul li:hover {
background-color: #cc3333;
cursor: pointer;
}
#hmenu ul li a {
color: #ffffff;
padding: 10px;
}
#hmenu ul {
background: #222 url('../images/overlay.png') repeat-x;
color: #fff;
text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.25);
cursor: pointer
}
.hiddenMenu {
display: none;
position: absolute;
top: 60;
left: 0;
z-index: 150;
background: #222 url('../images/overlay.png') repeat-x;
color: #fff;
text-shadow: 0 -1px 1px rgba(0, 0, 0, 0.25);
cursor: pointer;
width: inherit;
}
(sorry for the formatting, bit new to this, but you can apply source formatting in your editor I guess. I changed the navs to have the id and changed the HTML nav to be div. That's it.
HTML:
<div id="hmenu">
<ul>
<li>
menu1
</li>
<li>
menu2
<div id="items" class="hiddenMenu">
submenu1
submenu2
submenu3
submenu4
</div>
</li>
<li>
menu3
</li>
<li>
menu4
</li>
</ul>
</div>
You cannot have a tag named nav change it to div and try again.