drop down is moving the entire site content - html

.menu
{border-left: 1px solid #e9e9e9; border-right: 1px solid #e9e9e9; border-top: 1px solid #e9e9e9; overflow: hidden;}
.navbar {
}
.navbar > .active > a
{font-size: 14px; color: #3fbad8; font-family: 'open_sansbold'; background-image: none;
background:#f7f7f7; border: none; text-shadow: none; box-shadow: none;
}
.navbar > .active > a:hover{
box-shadow: none; background: #fff; color: #6f7678;
}
.navbar > li{
border-right: 1px solid #e9e9e9; float: left;display: block;position: relative; z-index:1000;}
.navbar > li>ul{display:none; position:relative;z-index:99}
.navbar > li > a { display:block;
color: #6f7678; padding: 25px; text-shadow: none; font-family: 'open_sansbold';
}
.navbar > li > a:hover{
background: #f7f7f7; color: #3fbad8;
}
.navbar > li:hover ul{display:block; postion:absolute;}
.navbar > li:hover li{float:none;}
.navbar . > li:hover li a:hover{background: #f7f7f7; color: #3fbad8;
}
#sub{
z-index:3;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
<div class="menu">
<div class="navbar">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<i class="fw-icon-th-list"></i>
</a>
<div>
<ul class="nav">
<li class="active">Home</li>
<li>About</li>
<li>Services
<ul class="nav"> <li>Printer Service</li>
<li>Computer Support</li>
<li>Email Support</li>
<li>Virus Support</li>
</ul></li>
<li>Testinominals</li>
<li>Price</li>
<li>Contact</li>
</ul>
<div runat="server" class="search-form">
Call Now +1-xxxxxxxxx
</div>
</div>
</div>
</div>
<!-- Menu ends -->
I have changed the position: relative; to position: absolute; however now the drop down goes back to the slide show. I tired a lot to fix this issue still I am unable to do it. Please guide me some one in a right way.

Add this
.menu{
position:absolute;
z-index:1000; //can be any number, but should be high enough to ensure it remains on top
}
It will take the menu out of the normal stacking order - allowing its contents to also be free of the normal DOM flow. That way when you open it, it will sit above the page content without pushing it down.
You will have to add margin to the top of your main content section equal to the height of your closed nav bar so that the content is not hidden behind the nav. You also need to apply the z-index to ensure that it remains on top of any other absolutely positioned elements on the page.

Related

Resolve shifts in CSS nav menu

I have shifts in my NAV menu that I am having trouble resolving. The menu is CSS & HTML based. Issue 1 > Mousing over Headings 1 through 4 causes a slight shift to the right of any headers to the right. How do I stop that? Issue 2 > Mousing over Header4 reveals a sub menu that initially appears fine. But when you hover over the sub menu the item of focus gets larger than the other sub menu items, so it looks sloppy. How do I correct this? Issue 3 > The Setting menu's sub menu (last menu item) expands in width when the sub menu is hovered over. I'd like it to be the same width whether it is being hovered over or not. How? Perhaps the same answer as #2.
Lastly, a general observation I'd like some feedback on. My original CSS for this NAV seemed pretty straight forward to me. As I've observed things that need to be "adjusted" I've added a tweak here, another there, and still another there, until now it seems completely convoluted. Is this common, or am I just mucking things up with bad tweaks? Thanks for your help.
CSS:
/* NAVIGATION */
#menu{
padding 0;
margin: 0;
}
.nav{
margin: 0;
padding: 0;
}
.nav ul{
padding: 0;
background-color: #003366;
}
.nav ul li{
display: inline-block; /*added*/
padding: 10px 22px 10px;
border-right: 1px solid #dadada;
position: relative;
background-color: #003366;
}
.nav ul li:hover{
background-color: #336699;
/* Adding the padding makes the hover selection not jump */
padding: 10px 22px 10px 26px;
left: -4px;
}
.nav ul li:hover ul{
display: block;
position: absolute;
}
.nav ul li a{
text-decoration: none;
color: #FFFFFF;
}
.nav ul li ul{
display: none;
left: 0px;
/*width: 403px;*/
margin-top: 10px;
padding-top: 0px;
box-shadow: 0px 1px 1px rgba(85, 85, 85, 0.75);
border-top: 1px solid #dadada;
}
.nav ul li ul li{
width: 143px;
border-bottom: 1px solid #dadada;
background-color: #336699;
}
.nav ul li ul li:hover{
background-color: #FFF8DC;
left: 0px;
}
.nav ul li ul li a{
text-decoration: none;
color: #FFFFFF;
}
.nav ul li ul li:hover a{
color: #000;
}
#settings {
padding: 6px 22px;
/*vertical-align:middle;*/
float:right;
border-right:none;
}
#settings:hover {
padding: 6px 18px;
}
#settings > ul {
position: absolute;
left: -124px;
top: 27px;
}
Web Page:
<?php
$access = 0
?>
<html>
<head>
<title>Nav</title>
<link rel="stylesheet" href="basicnav2.css"/>
</head>
<body>
<div id="menu">
<nav class="nav">
<ul>
<li>
Heading1
</li>
<li>
Heading2
</li>
<li>
Heading3
</li>
<li>
Heading4
<ul>
<li>
Item 1
</li>
<li>
Item 2
<li>
</ul>
<li>
Heading5
</li>
<?php
if ($access < 2)
{ ?>
<li id="settings">
<img src="images/settings.png" alt="Settings" height="25" width="25">
<ul id ="settings ul">
<li>
Logout
</li>
</ul>
</li>
<?php
} ?>
</ul>
</nav>
</div>
<div id="textarea">
<p>This is sample text.</p>
</div>
</body>
</html>
What is the reason for this part of your code:
/* Adding the padding makes the hover selection not jump */
padding: 10px 22px 10px 26px;
left: -4px;
Removing it appears to fix the problem at my end.
Issue1:
The expansion of li elements is caused due to addition of
left: -4px;
in .nav ul li:hover css section
However, removing it is causing little space on left of each li.
Issue 2 solution is removing the padding in the same above css section :
padding: 10px 22px 10px 26px;
Instead just use below line to jump to sub-menu:
padding-bottom: 10px;
Demo : http://jsfiddle.net/pdfn0auw/2/
Edit : new demo included

How to make the sub-menu be the same width as the parent menu?

I am trying to build a simple CSS navigation bar with a drop down menu, I am new to CSS and I am having a hard time to get my drop down menu to work. My main problem from the my drop-down menu is that I cannot get my sub-menu to be the same size as my main menu. One of my sub-menu's work the other one does not work?
---- HTML CODE ---
<nav id = "navigation" role:navigation>
<img src="logo_dark.png" id = "logo" />
<ul id="menu">
<li id="intresting_stuff">
<a href = "#" >
Interesting Stuff
<ul class="sub_menu" id="sub_menu">
<li id="classic">Science</li>
<li id="strategy">Technology</li>
<li id="sports">Comedy</li>
</ul>
</a>
</li>
<li id="games">
<a href = "#" >
Games
<ul class="sub_menu" id="sub_menu">
<li id="classic">Classic Games</li>
<li id="strategy">Strategy Games</li>
<li id="sports">Sports Games</li>
<li id="adventure">Adventure Games</li>
<li id="random">Random Games</li>
</ul>
</a>
</li>
<li id="home">
<a href = "#" >
Homes
<span>
</span>
</a>
</li>
</ul>
</nav>
----- CSS CODE -----
#navigation
{
display:block;
background: linear-gradient(to bottom, rgba(0,81,222,0.9)0,rgba(212,212,212,0.15)100%);
color: white;
width : 100%;
height:100%;
border-radius:5px;
-webkit-box-shadow: 0 8px 6px -6px black;
-moz-box-shadow: 0 8px 6px -6px black;
box-shadow: 0 8px 6px -6px black;
}
#navigation li a
{
display:inline-block; makes the list go from left to right
list-style: none;
padding-top:15px;
padding-bottom:15px;
padding-left:23px;
padding-right:23px;
float: right;
font-family: 'Oswald', sans-serif;
font-style:bold;
font-size: 20px;
color: white;
text-decoration: none;
}
/*This is the stuff for the drop down menu..*/
/*Initialize*/
ul#menu, ul#menu ul.sub_menu {
float:right;
display: flex;// alows the website to flex if necessary
flex-wrap: wrap;
justify-content: flex-start;
padding:0;
margin: 0;
}
ul#menu li, ul#menu ul.sub_menu li {
list-style-type: none;
display: inline-block;
}
/*Link Appearance*/
ul#menu li ul.sub_menu li a {
text-decoration: none;
color: #fff;
background: linear-gradient(tobottom,rgba(201,198,189,.5)0,rgba(212,212,212,0.15)100%);
padding:0px;
display:inline-block;
text-align:center;
font-size:19px;
width: 100%;
}
#intresting_stuff
{
border-left: 1px solid gray;
}
#games
{
border-left: 1px solid gray;
border-right: 1px solid gray;
}
/*Make the parent of sub-menu relative*/
ul#menu li {
position: relative;
float:right;
}
/*sub menu*/
ul#menu li ul.sub_menu {
margin:0;
padding:0;
display:none;
position: absolute;
top: 30px;
left: 0;
}
#classic:hover, #strategy:hover, #sports:hover, #adventure:hover,#random:hover
{
background:linear-gradient(to bottom, rgba(222,152,0,0.8) 0,rgba(212,212,212,0.4)100%);
}
#science:hover, #technology:hover, #comedy:hover
{
background:linear-gradient(to bottom, rgba(222,152,0,0.8) 0,rgba(212,212,212,0.4)100%);
}
#games:hover, #intresting_stuff:hover, #home:hover
{
background:linear-gradient(to bottom, rgba(222,152,0,0.8) 0,rgba(212,212,212,0.4)100%);
}
ul#menu li:hover ul.sub_menu {
display:block;
}
Your code is pretty messy, and you have some random <a> tags in the <ul>. I dropped your code in a jsfiddle and I think I understand what you are trying to do.
A lot of your issue revolves around floating left and right in the same divs, etc...
Take a look HERE for a working solution you can copy and paste. Specifically, take note of the hover elements and use of the visibility: visible; class property.

Why doesn't this CSS style my elements correctly?

I'm trying to have an inline-block navigation bar. When someone hovers over the li, I want it to change background colors - simple enough.
It appears as though my code causes the background to be off about 2 inches.
Here is the offending code -
css-
#mainNav {
width: 100%;
background:#bbb;
border-right: 2px solid #777;
border-left: 2px solid #777;
border-bottom: 2px solid #555;
}
#mainNav ul li {
display: inline-block;
line-height:40px;
font-size: 20px;
padding: 0 15px 0 15px;
border-right: 2px solid #777;
}
#mainNav ul li.active {
background:#aaa;
}
#mainNav ul li:hover {
background:#aaa;
}
html-
<div class='container_12'>
<nav id="mainNav">
<ul>
<li class='active'><a href='#'>Home</a></li>
<li><a href='#'>Games</a></li>
<li><a href='#'>Forums</a></li>
</ul>
</nav>
</div>
Screenshot:
Give margin-left to li will solve the problem.
DEMO
It should also be :
#mainNav ul li:active {
background:#aaa;
}
Just like hover is coded out. Still not sure about the original question though.

CSS tabs menu looks ugly when changing browser-zoom

Please look at my CSS Tabs menu: http://jsfiddle.net/NoGo/3Spru/
It uses the YAML 4 CSS Framework form yaml.de (Edit 2019: not actively developed anymore)
The Tabs are: Home | Users | Map
My HTML:
<nav>
<div class="ym-wrapper">
<div class="ym-wbox">
<ul>
<li>
<a href="#">
<div>Home <i class="icon-home"></i></div>
<span>Go to Main Page</span>
</a>
</li>
<li class="active">
<a href="#" class="">
<div>Users <i class="icon-search"></i></div>
<span>Search User Accounts</span>
</a>
</li>
<li>
<a href="#">
<div>Map <i class="icon-globe"></i></div>
<span>Users near you</span>
</a>
</li>
</ul>
</div>
<div class="ym-clearfix"></div>
</div>
</nav>
The CSS:
header nav {
clear: both;
width:100%;
position:relative;
white-space: nowrap;
padding-top:10px;
border-bottom: 2px solid #CA278C;
}
header nav ul {
list-style: none;
padding:0;
margin:0;
display:inline;
}
header nav ul li {
display: inline-block;
border-top: 2px solid transparent;
margin: 0 5px -2px 0;
background-color: #f0f0f0;
border-bottom: 2px solid #CA278C;
line-height: 180%;
}
header nav ul li.active,
header nav ul li:hover {
border-top: 2px solid #CA278C;
border-bottom: 2px solid #fff;
background-color: #fff;
}
header nav ul li.active {
border-right: 2px solid #CA278C;
border-left: 2px solid #CA278C;
}
header nav ul li a {
display: inline-block;
padding: 5px 16px;
}
header nav ul li a div {
text-transform: uppercase;
font-weight: bold;
font-size: 16px;
}
header nav ul li a span {
font-size: 11px;
color: #999
}
header nav [class^="icon-"],
header nav [class*=" icon-"] {
vertical-align: baseline;
line-height: inherit;
opacity: 0.7;
}
My problem: When I change browser zoom, the bottom-line looks ugly. Is there a better way than working with margin-bottom: -2px on li elements?
I could get it to look a lot better by using subpixel positioning and setting the margin-bottom and border-width to -1.5px and 1.5px respectively. It looks fine here at jsFiddle - with minimal effort - on 100% up to somewhere close to 200%, and you could probably get it to look even better at other zoom levels by going further down the subpixel rendering path.
But then it dawned on me that you don't really need to have that bottom border on the inactive tabs, just set the margin-bottom on the tabs to 0px and then set the margin-bottom at the .active and :hover class to -2px. This will automatically look fine on any zoom level, as you won't have to worry about 'lineing up the lines' at all. Here's a jsFiddle for this approach.
header nav ul li {
display: inline-block;
margin: 0 5px 0 0;
border-top: 2px solid transparent;
background-color: #f0f0f0;
line-height: 180%;
position: relative;
}
header nav ul li.active,
header nav ul li:hover {
border-top: 2px solid #CA278C;
border-bottom: 2px solid #FFF;
background-color: #fff;
margin-bottom: -2px;
}

HTML and CSS browser compatibility issue

I have originally created my navigation in Chrome in which the outcome fits perfectly to my needs. I have then found out that Mozilla Firefox won't output the same result, the drop-down menus under Member Action and Admin Related will display vertically instead on horizontally as i wanted. However my biggest dissapointment was testing the navigation in Internet Explorer which won't even show the drop-down menus.
I would really appreciate someone checking the below code and your feedback, Thanks.
Solved the problem by changing one of the lines in css;
navigation ul li {float: left; list-style:none; }
HTML
<div id="navigationContainer">
<div id="navigation">
<ul>
<li class="borderleft">Home </li>
<li>Register </li>
<li>Search cars</li>
<li>Display all cars</li>
<li>Member Actions
<ul> <!-- Open drop down menu -->
<li class="bordertop">Login</li>
<li class="floatLeft">Member Area</li>
<li>Reservation</li>
<li>Contact us</li>
<li>Admin Related
<ul>
<li class="bordertop">Insert new car</li>
<li>Delete a car</li>
</ul>
</li>
</ul>
</div>
</div>
</BODY>
</HTML>
CSS
* {padding: 0%; margin 0%; } /* Overwrites the browser stylesheet */
#navigationContainer {background:url(images/navi.png); width:100%;position: relative; white-space:nowrap; word-spacing:0; }
#navigation {width:1200px; height:65px; position: relative; font-family: Arial; margin: 2px auto; font-size: 125%; }
#navigation ul { list-style-type: none; }
#navigation ul li {float: left; position: relative; }
#navigation ul li a { border-right: 2px solid #e9e9e9; padding: 20px;
display: block; margin: 0 auto; text-align: center; color: black; text-decoration: none; }
#navigation ul li a:hover { background: blue; color: white; }
#navigation ul li ul { display: none; }
#navigation ul li:hover ul {display: block; position: absolute; }
#navigation ul li ul li {float:left; position:relative; }
#navigation ul li:hover ul li a { background: #12aeef; color: white; position:relative; margin: 0px auto; border-bottom: 1px solid white; border-right: 1px solid white; width: 119px; }
#navigation ul li:hover ul li a:hover { background: blue;}
.bordertop { border-top: 1px solid white; }
.borderleft { border-left: 2px solid #e9e9e9;}
Try this
http://jsfiddle.net/Vf3AJ/
Example from: http://www.cssnewbie.com/example/css-dropdown-menu/horizontal.html
EDITED
Misread horizontal for vertical. tested in IE10, FF, and Chrome
As a side note: horizontal menus have serious issues depending on the width of the viewers screen.
CSS
nav {
position: absolute;
top: 0;
right: 0;
margin: 0;
padding: 0;
}
nav li {
list-style: none;
float: left;
}
nav li a {
display: block;
padding: 3px 8px;
text-transform: uppercase;
text-decoration: none;
color: #999;
font-weight: bold;
}
nav li a:hover {
background: blue;
color: white;
}
nav li ul {
display: none;
}
nav li:hover ul, nav li.hover ul {
position: absolute;
display: inline;
left: 0;
width: 100%;
margin: 0;
padding: 0;
}
nav li:hover li, nav li.hover li {
float: left;
}
nav li:hover li a, navbar li.hover li a {
color: #000;
}
nav li li a:hover {
color: white;
}
HTML
<div id="navigationContainer">
<nav id="navigation">
<ul>
<li class="borderleft">Home
</li>
<li>Register
</li>
<li>Search cars
</li>
<li>Display all cars
</li>
<li>Member Actions
<ul>
<!-- Open drop down menu -->
<li class="bordertop">Login
</li>
<!-- A bordertop class is given to this listed element in order to style a top border for in in the external CSS file. -->
<li class="floatLeft">Member Area
</li>
<li>Reservation
</li>
</ul>
</li>
<li>Contact us
</li>
<li>Admin Related
<ul>
<li class="bordertop">Insert new car
</li>
<li>Delete a car
</li>
</ul>
</li>
</ul>
</nav>
</div>