I am trying to make a hoverable dropdown menu and the items of the dropdown are overlapped. I don't know how the CSS should be, but I tried to modify each class, but still doesn't work.
I also tried to modify the display of links, but that doesn't work. Here is the code I made:
<style>
#menu
{
margin:0;
font-size: 30px;
border-bottom: 1px solid;
text-align: center;
}
#menu a
{
color:#900;
text-decoration:none;
}
#menu .subitem a{
display: block;
padding: 12px 16px;
z-index: 1;
background-color: #f1f1f1;
border-bottom: 1px solid;
}
#menu a:hover
{
text-decoration:underline;
}
.item{
position: relative;
display: inline-block;
border-right: 0.5px solid;
padding-right: 30px;
padding-left: 30px;
}
.subitem{
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
left: 0;
z-index: 1;
}
#menu .item:hover .subitem{
display: block;
}
</style>
<div id="navWrapper">
<ul id="menu">
<li class="item">Small Things
<ul class="submenu">
<li class="subitem">Gnomes</li>
<li class="subitem">Fairies</li>
<li class="subitem">Elves</li>
<li class="subitem">Leprechauns</li>
</ul>
</li>
<li class="item">Big Things
<ul class="submenu">
<li class="subitem">Loch Ness Monster</li>
<li class="subitem">Ogres</li>
<li class="subitem">Giants</li>
<li class="subitem">Dragons</li>
</ul>
</li>
</ul>
</div>
I want to display properly each item when I hover with the mouse like it is in this
image.
You confused your .submenu with .subitem:
#menu
{
margin:0;
font-size: 30px;
border-bottom: 1px solid;
text-align: center;
}
#menu a
{
color:#900;
text-decoration:none;
}
#menu .subitem a{
display: block;
padding: 12px 16px;
z-index: 1;
background-color: #f1f1f1;
border-bottom: 1px solid;
}
#menu a:hover
{
text-decoration:underline;
}
.item{
position: relative;
display: inline-block;
border-right: 0.5px solid;
padding-right: 30px;
padding-left: 30px;
}
.subitem {
/* display: none; <- get rid of that */
/* position: absolute; <- get rid of that, otherwise all your subitems will be in the top left corner */
background-color: #f1f1f1;
min-width: 160px;
left: 0;
z-index: 1;
}
.submenu {
position: absolute; /* <- put it here */
display: none; /* <- put it here */
list-style-type: none;
left:-40px;
top: 30px;
}
#menu .item:hover .submenu {
display: block;
}
<div id="navWrapper">
<ul id="menu">
<li class="item">Small Things
<ul class="submenu">
<li class="subitem">Gnomes</li>
<li class="subitem">Fairies</li>
<li class="subitem">Elves</li>
<li class="subitem">Leprechauns</li>
</ul>
</li>
<li class="item">Big Things
<ul class="submenu">
<li class="subitem">Loch Ness Monster</li>
<li class="subitem">Ogres</li>
<li class="subitem">Giants</li>
<li class="subitem">Dragons</li>
</ul>
</li>
</ul>
</div>
Related
I'm having trouble aligning my drop down menu in my nav bar, I've tried every suggestion out there. I've tried left, float: left, right, and pretty much everything else. I think it is possibly something interfering. The drop down menu has everything aligned from center to right of the parent menu item.
https://jsfiddle.net/ethacker/j7tgq95j/3/
My html code:
<header>
<nav>
<h1> Welcome to Mommy Madness</h1>
<ul>
<li class="parentMenu">Home
<ul class="sub-menu">
<li>About</li>
<li>Contact</li>
</ul>
</li>
<li class="parentMenu">Pregnancy
<!--
Gender Predictions:
Old Wive's Tale
Boy vs Girl- The Ramzi Method
-->
<ul class="sub-menu">
<li>Advice</li>
<li>Gender Predictions</li>
<li>Trying To Conceive</li>
</ul>
</li>
<li class="parentMenu">All About Baby
<ul class="sub-menu">
<li>Fetal Development</li>
<li>Guidelines </li>
<li> Milestones</li>
</ul>
</li>
<li class="parentMenu">Party Momma
<!--
Birthdays - Link to 1-10th bdays.
-->
<ul class="sub-menu">
<li>Pregnancy Announcement</li>
<li>Gender Reveal</li>
<li>Baby Shower</li>
<li>Birth Announcement</li>
<li> Birthdays</li>
</ul>
</li>
<li class="parentMenu">Stations
<ul class="sub-menu">
<li>Hospital Bag</li>
<li>Diaper Bag</li>
<li>Changing Station</li>
<li>Baby Gear</li>
</ul>
</li>
<li class="parentMenu">Memory Markers
<!--
Drop Down Menu:
DIY
Purchases
(Both to have holiday/event selectors on right of page)
-->
<ul class="sub-menu">
<li>DIY</li>
<li>Purchases</li>
</ul>
</li>
<li class="parentMenu">Reviews
<ul class="sub-menu">
<li>Games</li>
<li>Gear</li>
<li>Learning</li>
</ul>
</li>
<li class="parentMenu">Blog
<ul class="sub-menu">
<li>Fit Momma</li>
<li>Minimal Momma</li>
<li>Modern Momma</li>
<li>Organic Momma</li>
<li>Organizing Queen</li>
<li>Savings Savvy</li>
<li>Tech Savvy</li>
<li>Traditional Momma</li>
</ul>
</li>
</ul>
</nav>
My css code:
body {
background-color: beige;
color: lightblue;
padding: 0;
margin:0;
}
header {
background-color: lightblue;
padding: 5px 0;
margin: 0;
}
header h1 {
color: cadetblue;
font-family: Arial;
margin: 0;
padding: 5px 15px;
display: inline;
}
.navMenu{
display: inline;
margin: 0;
}
.navMenu .parentMenu {
display: inline-block;
list-style-type: none;
background-color: lightgray;
padding: 5px 10px;
border: thin solid darkgray;
border-radius: 3px;
color: honeydew;
position: relative;
margin: 0;
}
.navMenu .parentMenu a{
color: azure;
}
.navMenu .parentMenu .sub-menu{
display: none;
}
.navMenu .parentMenu:hover .sub-menu{
display: block;
position: absolute;
list-style-type: none;
margin:0;
}
.parentMenu:hover .sub-menu li{
border: thin solid darkgray;
padding: 4%;
background-color: lightgray;
color: honeydew;
text-align: left;
white-space: nowrap;
width: 100%;
list-style-type: none;
margin: 0;
}
.parentMenu .sub-menu li:hover {
background-color: lightsteelblue;
}
.section {
background-color: wheat;
color: darkslategray;
padding: 5px;
float: left;
display: inline;
width: 63%;
margin: 0 1% 1% 1%;
border-radius: 10px;
border: thin solid khaki;
box-shadow: lightgray;
}
#about {
float: right;
width: 30%;
margin: 1% 1% 0 0;
text-align: center;
}
#home{
margin: 1% 0 1% 1%;
}
h4, h3 {
color: lightseagreen;
}
This will align the submenu to the left:
.navMenu .parentMenu .sub-menu {
display: none;
position:absolute;
list-style-type: none;
padding:0;
margin: 0;
left:-1px;
top:27px;
}
.navMenu .parentMenu:hover .sub-menu {
display: block;
}
https://jsfiddle.net/am13qur4/
you did not specify where you want to align your drop down elements. Do you want to align all to the right, center or left. I assumed left so try adding the code below. You may need to adjust the left attribute's value and your hover background styling too.
.sub-menu a{
position: absolute;
left: 3%;
}
Let me know if this helps. Stay warm!
I want the position of my navigation to be fixed. But when I change the position to "fixed" in nav, it looks very weird.
Here are two examples:
Without fixed position: https://jsfiddle.net/Timowo/3nrvch3c/
<nav>
<ul>
<li class="category">Contact</li>
<li class="category">Work</li>
<li class="category active">Home</li>
<li class="logotext">Logo</li>
</ul>
</nav>
With fixed position: https://jsfiddle.net/Timowo/5aock5k1/
<nav style="position: fixed;">
<ul>
<li class="category">Contact</li>
<li class="category">Work</li>
<li class="category active">Home</li>
<li class="logotext">Logo</li>
</ul>
</nav>
What do I have to change so it's inline but also fixed?
Thanks!
With position:fixed the element will collapse to the width of the widest descendant..in the absence of a defined width.
Just set width:100%
* {
box-sizing: border-box;
}
body {
margin: 0 auto;
background-color: red;
}
nav {
transition: all 0.2s ease-in-out;
position: fixed;
width: 100%;
}
nav ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: transparent;
}
nav ul li.logo {
padding: 14px;
float: left;
}
nav ul li.logotext {
font-family: Futura;
color: white;
font-size: 1.3em;
padding: 28px;
text-shadow: 3px 3px black;
}
nav ul li.category a {
display: block;
color: white;
text-align: center;
padding: 30px 20px;
text-decoration: none;
font-size: 1.2em;
float: right;
font-family: Futura;
text-shadow: 3px 3px black;
}
nav ul li.category:hover a {
background-color: #212121;
}
nav ul li.active a {
background-color: #212121;
}
<nav>
<ul>
<li class="category">Contact
</li>
<li class="category">Work
</li>
<li class="category active">Home
</li>
<li class="logotext">Logo</li>
</ul>
</nav>
I have been checking on other questions related to mine, and most of the time "text-align:center" is suggested. However, even if I implement it to my code, the navbar still doesn't center... Here's my code:
/* NAVIGATION BAR */
#navigation {
width:1300px;
height:auto;
}
#nav {
width: auto;
}
.ulnav {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
.navli {
float:left;
}
.navli a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 25px;
text-decoration: none;
}
.navli a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
.navli.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index:1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display:block;
}
.active {
background-color:green;
}
<div id="navigation">
<div id="nav">
<ul class="ulnav">
<li class="navli"><a class="active" href="#home">Home</a></li>
<li class="navli">Link</li>
<li class="dropdown navli">
Dropdown
<div class="dropdown-content">
Droplink 1
Droplink 2
</div>
</li>
<li class="dropdown navli">
Dropdown 2
<div class="dropdown-content">
Droplink 2.1
Droplink 2.2
Droplink 2.3
</div>
</li>
<li class="dropdown navli">
Dropdown 3
<div class="dropdown-content">
Droplink3.1
Droplink3.2
Droplink3.3
</div>
</li>
<li class="navli">Link 2</li>
</ul>
</div>
</div>
Thanks for any suggestions in advance!
remove float:left on your navli class ang set it to display:inline-block and add text-align:center on your #nav, and to center your #navigation add margin:0 auto;
/* NAVIGATION BAR */
#navigation {
width:1300px;
height:auto;
margin : 0 auto;
}
#nav {
width: auto;
text-align : center;
}
.ulnav {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
.navli {
/* float:left;*/
display : inline-block;
}
.navli a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 25px;
text-decoration: none;
}
.navli a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
.navli.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index:1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display:block;
}
.active {
background-color:green;
}
<div id="navigation">
<div id="nav">
<ul class="ulnav">
<li class="navli"><a class="active" href="#home">Home</a></li>
<li class="navli">Link</li>
<li class="dropdown navli">
Dropdown
<div class="dropdown-content">
Droplink 1
Droplink 2
</div>
</li>
<li class="dropdown navli">
Dropdown 2
<div class="dropdown-content">
Droplink 2.1
Droplink 2.2
Droplink 2.3
</div>
</li>
<li class="dropdown navli">
Dropdown 3
<div class="dropdown-content">
Droplink3.1
Droplink3.2
Droplink3.3
</div>
</li>
<li class="navli">Link 2</li>
</ul>
</div>
</div>
You've used float:left on the li, which aligns them to left. I've removed it and added text-align:center to the ul
Is this what you're looking for?
/* NAVIGATION BAR */
#navigation {
width:1300px;
height:auto;
}
#nav {
width: auto;
}
.ulnav {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
text-align:center;
}
.navli {
display:inline-block;
}
.navli a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 25px;
text-decoration: none;
}
.navli a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
.navli.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index:1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display:block;
}
.active {
background-color:green;
}
<div id="navigation">
<div id="nav">
<ul class="ulnav">
<li class="navli"><a class="active" href="#home">Home</a></li>
<li class="navli">Link</li>
<li class="dropdown navli">
Dropdown
<div class="dropdown-content">
Droplink 1
Droplink 2
</div>
</li>
<li class="dropdown navli">
Dropdown 2
<div class="dropdown-content">
Droplink 2.1
Droplink 2.2
Droplink 2.3
</div>
</li>
<li class="dropdown navli">
Dropdown 3
<div class="dropdown-content">
Droplink3.1
Droplink3.2
Droplink3.3
</div>
</li>
<li class="navli">Link 2</li>
</ul>
</div>
</div>
I am trying to make a miniature vertical bar like in this site, where they have the navigation and the vertical bars in between each link. I have tried the solution to a previous question, but when I tried to use 'margin-left' to move the text, the bar wouldn't stay between each link, it'd to this.
HTML
<div id="nav-clearfix">
<div id="nav">
<ul class="nav-pages">
<li>HOME</li>
<li><div class="mini-divider"></div></li>
<li>ROSTER</li>
<li><div class="mini-divider"></div></li>
<li>GALLERY</li>
<li><div class="mini-divider"></div></li>
<li>ABOUT US</li>
<li><div class="mini-divider"></div></li>
<li>SPONSORS</li>
</ul>
</div>
</div>
CSS
#nav-clearfix {
width: 100%;
height: 100px;
background: #000;
}
#nav {
margin-left: 10%;
width: 100%;
}
.nav-pages {
padding-top: 10px;
}
.mini-divider {
position: absolute;
top: 26%;
bottom: 71%;
border-left: 1px solid white;
}
.nav-pages li, .mini-divider {
float: left;
margin-left: 50px;
}
CSS
.nav-pages li:not(:last-child) a:after{
content: "";
/* width: 0px; */
background: white;
margin-left: 20px;
position: absolute;
height: inherit;
color: white;
border: 1px solid white;
height: 15px;
}
Remove The Border Related HTML & CSS
<li><div class="mini-divider"></div></li>
DEMO
You can also use + css selector to give border to the next element no need to add extra element for border
added
*{
margin: 0;
padding: 0;
}
for removing default styles given by browsers
* {
margin: 0;
padding: 0;
}
#nav-clearfix {
width: 100%;
height: 100px;
background: #000;
}
#nav {
width: 100%;
}
.nav-pages {
padding-top: 10px;
text-align:center;
}
.nav-pages li {
display: inline-block;
padding: 0 10px;
}
.nav-pages li + li {
border-left: 1px solid white;
}
<div id="nav-clearfix">
<div id="nav">
<ul class="nav-pages">
<li>HOME</li>
<li>ROSTER</li>
<li>GALLERY</li>
<li>ABOUT US</li>
<li>SPONSORS</li>
</ul>
</div>
</div>
Use this .separator class for vertical separator.
CSS
ul > li{
float: left;
display: block;
position: relative;
}
ul > li > a{
padding: 4px 6px;
display: block;
}
.separator {
background: none repeat scroll 0 0 #222;
border-left: 1px solid #333;
float: left;
height: 30px;
width: 1px;
}
HTML
<ul>
<li >
<a href="#" >Home</a>
</li> <span class="separator"></span>
<li> Link 1 </li> <span class="separator"></span>
<li > Link 2 </li> <span class="separator"></span>
<li> Link3 </li> <span class="separator"></span>
<li > Contact </li>
</ul>
jsfiddle: demo
I have a nav menu that has different size cells for each item. Under each item I want a triangle image to indicate the active menu item.
How can I make the :after reflect the same size as the parent so that I can have the content of the :after centered properly?
Code for the menu:
<div class="nav-collapse collapse">
<ul class="nav nav-pills">
<li>Clients</li>
<li>Solutions</li>
<li>Services</li>
<li>Your Business</li>
<li>Security</li>
<li>Partners</li>
<li>Contact</li>
</ul>
</div>
The way here is use absolute position on the :after element and use the li or a tag parent as relative. Like this:
.nav > li a {
position: relative;
}
.nav > li a:after {
content: "\25B2";
position: absolute;
left: 50%;
transform: translate(-50%, -100%);
}
Check The Snippet
* {
margin: 0;
padding: 0
}
.nav > li {
height: 70px;
line-height: 70px;
background: orange;
list-style: none;
margin: 1px;
float: left;
}
.nav > li a {
position: relative;
padding: 0 15px;
display: block;
color: white;
font-family: 'verdana';
text-decoration: none;
transition: background .3s ease
}
.nav > li a:hover {
background: red;
}
.nav > li a:after {
content: "\25B2";
position: absolute;
color: white;
top: 100%;
line-height: normal;
left: 50%;
transform: translate(-50%, -100%);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="nav-collapse collapse">
<ul class="nav nav-pills">
<li>Clients
</li>
<li>Solutions
</li>
<li>Services
</li>
<li>Your Business
</li>
<li>Security
</li>
<li>Partners
</li>
<li>Contact
</li>
</ul>
</div>
Try this css, include text in the content: " " and set the color to transparent via rgba. then set background to an image
.nav-pills {
width: 100%;
display:block;
list-style:none;
}
.nav-pills li{
display:inline;
float:left;
margin: 0 20px;
padding:4px 10px
background:#d7d7d7;
text-align:center;
}
.nav-pills li::after {
content: " Image";
padding: 4px 10px;
background:url(images/image.png);
background-color:orange;
color: rgba(255,255,255,0);
display:block;
}
Check out my codepen here