I am new to CSS and I need help with the navigation bar. I need to get the sub-topic right under the ABOUT US part but I cannot get it, it appears all the way to the right. Anything would be appreciated.
I can provide the HTML file if you need.
CSS:
container{
position: relative;
height: 70px;
width: 1100px;
}
.masthead{
background: #039be5;
width: 100%;
top: 0;
position: fixed;
color: white;
}
.logo{
position: relative;
float: left;
left: 90px;
font-family: Josefin Slab;
font-size: 21px;
top: 17px;
}
.logo h1 a {color: white; text-decoration: none; }
h1{
margin: 0;
}
a:link {color: white; text-decoration: none; }
a:visited {color: white; text-decoration: none; }
a:hover {color: white; color: black; }
a:active {color: white; text-decoration: none; }
#navcontent{
word-spacing: 4px;
}
li{
position: relative;
left: 155px;
list-style: none;
font-family: Raleway;
float: left;
margin-left: 21px;
padding-top: 15px;
font-size: 20px;
}
.navigation{
float: right;
}
.navigation ul>li ul{
height: 100%;
position: relative;
bottom: 100%;
}
.navigation ul>li ul>li{
bottom: 0px;
display: none;
}
.navigation>ul>li:hover ul>li{
display: block;
}
.navigation>ul>li a:hover {
text-decoration: none;
cursor:pointer;
}
HTML
<div class="masthead">
<div class="container">
<div class="logo">
<h1> MY SITE</h1>
</div>
<div class="navigation">
<ul>
<li>Courses
</li>
<li>Places
</li>
<li>More
<ul>
<li>Share
</li>
<li> Help
</li>
</ul>
</li>
<li id="navcontent">|| Sign In
</li>
<li>Sign Up
</li>
</ul>
</div>
</div>
</div>
Fiddle
To the point,,
CSS
ul{
list-style:none;
position:relative;
float:left;
margin:0;
padding:0
}
ul a
{
display:block;
color:#333;
text-decoration:none;
font-weight:700;
font-size:12px;
line-height:32px;
padding:0 15px;
}
ul li
{
position:relative;
float:left;
margin:0;
padding:0
}
ul li:hover
{
background:#f6f6f6
}
ul ul
{
display:none;
position:absolute;
top:100%;
left:0;
background:#fff;
padding:0
}
ul ul li
{
float:none;
width:200px
}
ul ul a
{
line-height:120%;
padding:10px 15px
}
ul ul ul
{
top:0;
left:100%
}
ul li:hover > ul
{
display:block
}
Live result here.
Hope this help
UPDATE
Ok, due to what Jon P ask I will describe this code.
Actually the main keys are :
ul ul
{
display:none;
position:absolute;
top:100%;
left:0;
background:#fff; /*remove, no effect*/
padding:0 /*remove, no effect*/
}
First, we make the child(<ul>) become hidden with display: none and give it properties position:absolute, top:100%, left:0; to let it under the MORE link
And then what we want? show it when we hover the MORE link. to do so, just do simple by making that child(<ul>) visible. Of course, we use this property :
ul li:hover > ul
{
display:block
}
Related
I have a menu with dropdown option, I'm trying to align the dropdown menu under the respective item selected from list. So far is aligned to the left, the dropdown ul list is inside the element that should display the dropdown list.
I'm not sure about what I'm doing wrong here, some suggestion?
DEMO
HTML
<div id="menu">
<div id="menu-wrapper">
<img id="home-icon" src="images/home.svg" />
<nav id="menu">
<ul>
<li>SUBSCRIBE</li>
<li>NEWS</li>
<li>MARINA GUIDE</li>
<li class="submenu">PRACTICAL
<ul>
<li>Glossary</li>
<li>Tips</li>
</ul>
</li>
<li>OUT AT SEA</li>
<li>GEAR</li>
<li>FORUM</li>
</ul>
</nav>
<div id="menu-icon-container">
<img id="menu-icon" src="images/menu.svg" />
</div>
<div id="menu-icon-container">
<img id="menu-icon" src="images/search.svg" />
</div>
</div>
CSS
#menu-icon-container {
position: relative;
float: right;
height: 100%;
width: 60px;
background-color: ;
}
#menu-icon-container:hover {
background-color: #bf1b33;
cursor: pointer;
}
#menu-icon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
-webkit-transform: translate(-50%,-50%);
cursor: pointer;
}
#menu ul {
list-style:none;
position:relative;
float:left;
margin:0;
padding:0;
margin-left:20px;
}
#menu ul li {
display: inline;
}
#menu ul li a {
color: #00599b;
padding: 0px 15px;
text-decoration: none;
border-radius: 4px 4px 0 0;
font-family: 'Open Sans', sans-serif;
}
#menu ul li a:hover {
border-bottom: 2px solid #bf1b33;
}
#menu ul ul
{
display:none;
position:absolute;
top:100%;
background: fuchsia;
padding:0
}
#menu ul ul li
{
float:none;
width:200px
}
#menu ul ul a
{
line-height:120%;
padding:10px 15px
}
#menu ul li:hover > ul
{
display:block
}
Add position: relative; to #menu ul li { and left:0; to #menu ul ul will make it proper below the selected.
#menu ul li {
display: inline;
position: relative;
}
#menu ul ul
{
display:none;
position:absolute;
top:100%;
left:0;
background: fuchsia;
padding:0
}
Fiddle
I'm trying to create a pure css drop down menu. Everything works fine except for when I hover to drop the menu down, the entire nav bar also gets expanded and I don't want it to do that. Here is my code:
.nav-bar {
list-style:none;
}
#right {
padding-right: 100px;
}
#right li {
display: inline;
float: right;
padding: 3% 0 0.5% 0;
margin-top: -30px;
}
#right li img {
max-width: 70%;
max-height: auto;
}
#media screen and (max-width: 1000px) {
#right {
display: none;
}
}
#nav-refer {
padding: 5% 15% 5% 15%;
border-radius: 25px;
background: #FFC52D;
font-family: 'Bebas Neue Bold';
font-size: 22px;
text-align: center;
color: black;
text-decoration: none;
}
#media (max-width: 1000px) {
#nav-refer {
display: none;
}
}
#left {
padding-left: 100px;
}
#left li {
display: inline;
float: left;
display: block;
margin: -5px 0 0 -30px;
}
#left li img {
padding: 0 0 0 15px;
}
.drop_menu {
background: white;
padding:0;
margin:0;
list-style-type:none;
/*height: 30px;*/
}
.drop_menu li {
float:left;
}
.drop_menu li a {
padding:9px 20px;
display:block;
color: black;
text-decoration:none;
font-family: 'Bebas Neue Regular';
font-size: 22px;
}
.drop_menu li a img {
width: 60%;
height: auto;
padding: 0px;
}
/* Submenu */
.drop_menu ul {
position: absolute;
left:-9999px;
top:-9999px;
list-style-type: none;
}
.drop_menu:hover {
display:block;
height: 110px;
}
.drop_menu li:hover {
position:relative;
height: 30px;
}
.drop_menu li:hover ul {
left:70px;
top:50px;
background: white;
padding:0px;
}
.drop_menu li:hover ul li a {
padding:10px;
display:block;
width:168px;
text-indent:15px;
background-color: white;
}
.drop_menu li:hover ul li a:hover {
background: #E6E6E6;
padding: 5px;
}
#media (max-width: 1000px) {
#left {
display: none;
}
}
<div class="nav-bar">
<ul id="left">
<ul class="drop_menu">
<li><img src={{asset('images/hamburger2.png')}}>
<ul>
<li>ABOUT</li>
<li>TESTIMONIALS</li>
<li>REFER-A-FRIEND</li>
<li>CONTACT</li>
</ul>
</li>
</ul>
<li><img src={{asset('images/shine2_logo.png')}}></li>
</ul>
<ul id="right">
<li>REFER FRIENDS</li>
<li><img src={{asset('images/twitter_Icon.png')}}></li>
<li><img src={{asset('images/instagram_Icon.png')}}></li>
<li><img src={{asset('images/facebook_Icon.png')}}></li>
</ul>
</div>
Ive updated your CSS, you had some styles in the wrong place and you were also expanding the height of the menu when you hovered on the first <li>.
I also updated the position of the .drop_menu li:hover ul { to be 100% from the top of the parent <li>.
.clearfix:before,
.clearfix:after{
content: "";
display: table;
clear: both;
}
.clearfix:after {
clear: both;
}
.drop_menu {
background: white;
padding:0;
margin:0;
list-style-type:none;
background: green;
}
.drop_menu > li {
float:left;
position:relative;
}
.drop_menu li a {
padding:9px 20px;
display:block;
color: black;
text-decoration:none;
font-family: 'Bebas Neue Regular';
font-size: 22px;
}
.drop_menu li a img {
width: 60%;
height: auto;
padding: 0px;
}
/* Submenu */
.drop_menu ul {
position: absolute;
left:-9999px;
top:-9999px;
list-style-type: none;
}
.drop_menu:hover {
display:block;
/* height: 110px; */
}
.drop_menu li:hover ul {
left:70px;
top: 100%;
background: white;
padding:0px;
}
.drop_menu li:hover ul li a {
padding:10px;
display:block;
width:168px;
text-indent:15px;
background-color: white;
}
.drop_menu li:hover ul li a:hover {
background: #E6E6E6;
padding: 5px;
}
<ul class="drop_menu clearfix">
<li>hamburger
<ul>
<li>ABOUT</li>
<li>TESTIMONIALS</li>
<li>REFER-A-FRIEND</li>
<li>CONTACT</li>
</ul>
</li>
</ul>
I am new to HTML/CSS so please don't hurt me :)
How can I center my navigation? I've researched as much as I can...
CSS:
#navigation ul {
font-family:Arial;
list-style-type:none;
margin:0;
padding:0;
width:auto;
height:auto;
text-align:center;
}
#navigation ul li {
display:inline-block;
margin-right:-2px;
position:relative;
}
#navigation ul li a {
display:inline-block;
padding:5px 10px;
background:#ccc;
color:#000;
text-decoration: none;
}
#navigation ul li a:hover {background: #666;}
#navigation ul ul {
position:absolute;
left:0;
width:200px;
transition:all .5s;
max-height: 0;
overflow: hidden;
}
#navigation ul.submenu li {
display:block;
}
#navigation ul.submenu li a {
display:block;
background:#fff;
color: #000;
}
#navigation ul.submenu li a:hover {background: #333;}
#navigation ul li:hover ul {
max-height: 10000px;
}
#navigation li {
font-family:Arial;
font-size:11px;
display:inline;
float:left;
background-color:#FFF;
}
#navigation a {
display:block;
width:60px;
background-color:#FFF;
}
#navigation.center {
display:block;
margin-left:auto;
margin-right:auto;
}
#navigation {
disply:inline-block;
height:50px;
}
HTML:
<div id="navigation">
<ul>
<li>Aperture Science
<ul class="submenu">
<li>GLaDOS</li>
<li>Testing Chambers</li>
<li>The Player (Chell)</li>
</ul>
</li>
</ul>
<ul>
<li>Black Mesa
<ul class="submenu">
<li>The Combine</li>
<li>The Resistance</li>
<li>The Player (Gordon Freeman)</li>
</ul>
</li>
</ul>
</div>
Any help would be great! Thanks!
(Yes, my starter site is on Half Life and Portal)
You can try using below html code and css
HTML:
<div id="navMenu">
<ul>
<li>
Black Mesa
<ul>
<li>GLaDOS</li>
<li>Testing Chambers</li>
<li>The Player (Chell)</li>
</ul>
</li>
<li>
Black Mesa
<ul>
<li>The Combine</li>
<li>The Resistance</li>
<li>The Player (Gordon Freeman)</li>
</ul>
</li>
</ul>
</div>
CSS
#navMenu {
margin: 0;
padding: 0;
text-align: center;
}
#navMenu ul {
margin: 0;
padding: 0;
line-height: 30px;
display: inline-block;
}
#navMenu li {
margin: 0;
padding: 0;
text-align: left;
float: left;
list-style: none;
position: relative;
background-color: #999;
border-radius: 5px;
}
#navMenu ul li a {
text-align: center;
text-decoration: none;
height: 30px;
width: 150px;
display: block;
color: #FFF;
border: 1px solid #FFF;
text-shadow: 1px 1px 1px #000;
}
#navMenu ul ul {
position: absolute;
visibility: hidden;
top: 32px;
}
#navMenu ul li:hover ul {
visibility: visible;
}
#navMenu li:hover {
background-color: #09F;
}
#navMenu ul li:hover ul li a:hover {
background-color: #CCC;
color: #000;
}
#navMenu a:hover {
color: #000;
}
fiddle : http://jsfiddle.net/Khumesh/adx2g1z0/
You need to adjust navigation Div by applying width and setting its margin property using css:
#navigation{
width:50%;
margin:0 auto;
}
Please refer to fiddle for demo
My menu item with a dropdown submenu expands each time I mouse over. Below is the HTML code for it.
<header id="header">
<div style="width:90%; margin:auto;">
<div id="logo">Inversion iDeas</div>
<nav id="nav">
<ul>
<li>welcome</span></li>
<li>Discover<br /><span class="desc">About Us</span>
<ul>
<li>Our Services</li>
<li>Content Marketing Strategy</li>
<li>Print & Digital Publishing</li>
<li>Direct Interactive Marketing</li>
<li>Social Media Marketing</li>
<li>Search Marketing</li>
<li>Video</li>
<li>Experiential Marketing Events</li>
<li>Current Media Ideas</li>
<li>Events</li>
<li>Web & Mobile</li>
<li>Leadership</li>
</ul>
</li>
<li>Experience<br /><span class="desc">media</span></li>
<li>Testimony<br /><span class="desc">Satisfied Clients</span></li>
<li>Reach Us<br /><span class="desc">contact us</span></li>
</ul>
</nav>
</div>
</header>
css
header {
width: 100%;
background:#000;
opacity:0.8;
height: 80px;
position: fixed;
margin-top: 30px;
z-index:999;
}
#logo a {
color: #fff;
text-decoration: none;
float: left;
font-size: 30px;
margin-top: 20px;
font-family:"century gothic";
font-weight: normal;
height:45px;
width:287px;
text-indent:-9999px;
background:url(../images/logo.png) 0 0 no-repeat;
}
#nav {
width: 800px;
position:fixed;
top:50px;
left:400px;
}
#nav ul{
list-style: none;
display: block;
margin: 0;
padding: 0;
}
#nav li{
float: left;
padding: 10px 20px 0 20px;
border-left:solid 1px #fff;
text-align:center;
height:40px;
display:block;
font-size:12px;
}
#nav li:first-child{
border-left:none;
}
#nav li a {
color: #fff; opacity:0.7; font-size: 16px; text-decoration: none; font-family: Verdana, Geneva, sans-serif;
}
#nav li a.active { color: #94c600; opacity:1;}
#nav li a:hover { color: #94c600; opacity:1; width:100%;}
#nav li ul { display: none;}
#nav li:hover ul {display: block; position: relative; top:8px; left:-20px; width:160px; padding:0;}
#nav li:hover li {float: none; font-size:12px; background:rgba(0,0,0,0.8); border-left:none; text-align:left; }
#nav li:hover li a {font-size:12px; padding:0; margin:0;}
#nav li:hover li a:hover {color:#94c600;}
.desc{
font-size:12px;
color:#333;
display: block;
}
position: relative; on the parent. position: absolute; on the child.
JSfiddle (please include one the next time you post)
I added some positioning to your CSS
#nav li ul { display: none; position: relative;}
#nav li:hover ul {display: block; position: absolute; top:48px; left:168px; width:160px; padding:20px 0 0 0;}
#nav li:hover li {float: none; font-size:12px; background:rgba(0,0,0,0.8); border-left:none; text-align:left;}
See working live here
http://codepen.io/jhawes/pen/lyevj
I have a CSS drop down menu which looks fine in firefox, chrome and most versions of IE.
But in IE8 the drop down menu disappears the second you move your mouse down onto it from the top menu bar.
I've been searching for an answer to this for a while now I found this answer here on stack
https://stackoverflow.com/a/10132588/2393553
And have amended my code accordingly. But I still cant get it to work :/
Here is my CSS
#navigation {
margin-top:-15px;
font-size: 14pt;
z-index:9000;
}
#navigation ul {
float: right;
list-style-type: none;
z-index:9000;
padding:0px;
margin:0px;
}
#navigation li {
float: left;
color: #505050;
position:relative;
z-index:9000;
right:0px;
display:block;
}
#navigation li ul
{
display: none;
z-index: 9000;
position:absolute;
top:100%;
left:0;
}
#navigation li ul.end
{
display: none;
z-index: 9000;
position:relative;
top:auto;
right:0;
}
#navigation a
{
display: block;
text-decoration: none;
color: #00529f;
padding: 5px 7px 5px 7px;
margin-left: 1px;
white-space: nowrap;
z-index: 9000;
}
#navigation li a:hover
{
background: #00529f;
color:#fff;
text-decoration: none;
z-index: 9000;
margin:0px;
display:block;
}
#navigation li:hover ul
{
display: block;
z-index:9000;
left:auto;
margin-left:0px;
}
#navigation li:hover li
{
float: none;
font-size: 18px;
text-align: left;
font-family: verdana;
z-index:9000;
border-top:1px solid #fff;
margin-left:0px;
}
#navigation li:hover a
{
background: #00529f;
color:#fff;
z-index:9000;
margin-left:0px;
}
#navigation li:hover li a:hover
{
background: #7ca7d8;
z-index:9000;
margin-left:0px;
}
and here is my HTML
<div id = "navigation">
<ul>
<li><?=get_content(1)?></li>
<li><?=get_content(2)?>
<ul>
<li><?=get_content(7)?></li>
<li><?=get_content(199)?></li>
<li><?=get_content(201)?></li>
<li><?=get_content(202)?></li>
</ul>
</li>
<li><?=get_content(1322)?>
<ul>
<li><?=get_content(3208)?></li>
</ul>
</li>
<li><?=get_content(3950)?></li>
<li><?=get_content(1825)?>
<ul>
<li><?=get_content(3972)?></li>
<li><?=get_content(1816)?></li>
<li><?=get_content(505)?></li>
</ul>
</li>
<li><?=get_content(4)?>
<ul class="end">
<li><?=get_content(4050)?></li>
<li><?=get_content(4005)?></li>
</ul>
</li>
</ul>
</div>
Could someone help please?
A quick edit to inform you that When testing this using IEtester it doesnt work in IE8. It also doesnt work on a co-worker machine who has IE8 installed. However when testing it with developer tools in IE10 setting the version back to IE8 it does work. I still have no solution :/
I used your code and remove the href code. It is working fine for me in IE8(i used ie developer tool to test this).
Here is the HTML i tested.
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
#navigation {
margin-top:-15px;
font-size: 14pt;
z-index:9000;
}
#navigation ul {
float: right;
list-style-type: none;
z-index:9000;
padding:0px;
margin:0px;
}
#navigation li {
float: left;
color: #505050;
position:relative;
z-index:9000;
right:0px;
display:block;
}
#navigation li ul
{
display: none;
z-index: 9000;
position:absolute;
top:100%;
left:0;
}
#navigation li ul.end
{
display: none;
z-index: 9000;
position:relative;
top:auto;
right:0;
}
#navigation a
{
display: block;
text-decoration: none;
color: #00529f;
padding: 5px 7px 5px 7px;
margin-left: 1px;
white-space: nowrap;
z-index: 9000;
}
#navigation li a:hover
{
background: #00529f;
color:#fff;
text-decoration: none;
z-index: 9000;
margin:0px;
display:block;
}
#navigation li:hover ul
{
display: block;
z-index:9000;
left:auto;
margin-left:0px;
}
#navigation li:hover li
{
float: none;
font-size: 18px;
text-align: left;
font-family: verdana;
z-index:9000;
border-top:1px solid #fff;
margin-left:0px;
}
#navigation li:hover a
{
background: #00529f;
color:#fff;
z-index:9000;
margin-left:0px;
}
#navigation li:hover li a:hover
{
background: #7ca7d8;
z-index:9000;
margin-left:0px;
}
</style>
</head>
<body>
<div id = "navigation">
<ul>
<li>sdfs</li>
<li>sdfs
<ul>
<li>sdfs</li>
<li>ddfsdfs</li>
<li>sdfsfsfsd</li>
<li>hdfgfd</li>
</ul>
</li>
<li>fhfgh
<ul>
<li>hkhfjf</li>
</ul>
</li>
<li>lghjn</li>
<li>tyjffgh
<ul>
<li>gfdhhgd</li>
<li>lhghjgjg</li>
<li>ccvcxv</li>
</ul>
</li>
<li>gfdfd
<ul class="end">
<li>fdfdfd</li>
<li>dgdfgdfgfd</li>
</ul>
</li>
</ul>
</div>
</body>
</html>