This is a pure CSS navbar I got from CSS Tricks. I've been racking my brain trying to figure out what's causing the blank, open, see-through space below each item on the drop-down menu, going over every CSS property, but I can't get it. You can see the image slider through them, and we don't want that. Can anyone help?
It's more obvious on the web than in the fiddle.
Here's the HTML:
<nav>
<ul class="nav"> <!-- Menu from https://css-tricks.com/targetting-menu-elements-submenus-navigation-bar/ -->
<li>Home</li>
<li>Services
<ul class="align-left">
<li>Drug Formulation</li>
<li>Analytical & Bioanalytical Services</li>
<li>Thermal Analysis</li>
<li>Custom Synthesis</li>
<li>Pharmacology & Toxicology</li>
<li>Regulatory Support for Drugs & Medical Devices</li>
<li>Materials Testing</li>
<li>Catalog of Chemical Reagents & Materials</li>
<li>Food Analysis</li>
</ul>
</li>
<li>Technologies
<ul class="align-left">
<li>API Micronization</li>
<li>Drug Delivery
<ul class="align-left">
<li>Sol-gel Encapsulation</li>
<li>Smart Hydrogels and Biomaterials</li>
<li>Electrorheologically-Controlled Drug Release</li>
<li>Polyphosphazenes</li>
</ul>
<li>Materials Science
<ul class="align-left">
<li>Coatings</li>
<li>Structural Materials</li>
<li>Viscosity Control: Non-aqueous Systems</li>
</ul>
</li>
</ul>
</li>
<li>Bio-Pharma Storage</li>
<li>About Us</li>
<li>News</li>
<li>Contact</li>
</ul>
</nav>
And the CSS:
nav {
display: block;
width:100%;
text-align: center;
}
nav ul {
margin: 0;
padding: 0;
list-style: none;
}
.nav a {
display: block;
background-color: #003399;
color: white;
text-decoration: none;
padding: .5em 1.4em .7em;
font-size: 75%;
letter-spacing: 1px;
position: relative;
}
.nav {
vertical-align: top;
display: inline-block;
border-radius: 6px;
}
.nav li { position: relative; }
.nav > li {
float: left;
border-bottom: 4px #aaa solid;
margin-right: 1px;
}
.nav > li > a {
margin-bottom: 1px;
}
.nav > li:hover, .nav > li:hover >a { border-bottom-color: #99ddff; }
.nav li:hover > a { color: #99ddff; }
.nav > li:first-child { border-radius: 4px 0 0 4px; }
.nav > li:first-child>a { border-radius: 4px 0 0 0; }
.nav > li:last-child {
border-radius: 0 0 4px 0;
margin-right: 0;
}
.nav > li:last-child >a { border-radius: 0 4px 0 0; }
.nav li li a { margin-top: 1px }
.nav li a:first-child:nth-last-child(2):before {
content: "";
position: absolute;
height: 0;
width: 0;
border: 5px solid transparent;
top: 50%;
right: 5px;
}
/* submenu positioning*/
.nav ul {
position: absolute;
white-space: nowrap;
border-bottom: 5px solid #99ddff;
z-index: 1;
left: -99999em;
}
.nav > li:hover > ul {
left: auto;
padding-top: 5px;
min-width: 100%;
}
.nav > li li ul { border-left: 1px solid #fff; }
.nav > li li:hover > ul {
/* margin-left: 1px */
left: 100%;
top: -1px;
}
/* arrow hover styling */
.nav > li > a:first-child:nth-last-child(2):before { border-top-color: white; }
.nav > li:hover > a:first-child:nth-last-child(2):before {
border: 5px solid transparent;
border-bottom-color: orange;
margin-top: -5px
}
.nav li li > a:first-child:nth-last-child(2):before {
border-left-color: #aaa;
margin-top: -5px
}
.nav li li:hover > a:first-child:nth-last-child(2):before {
border: 5px solid transparent;
border-right-color: orange;
right: 10px;
}
.align-left { text-align: left; }
.nav > li {
float: left;
border-bottom: 4px #aaa solid;
margin-right: 1px;
}
remove the margin-right :-)
Related
Hey i am having a bit of an issue. The right side of my nav when i hover over it moves the drop down menu a little more to the right. Every other nav is position to its absolute position...
nav {
padding-left: 5px
}
nav .main-nav {
height: 80px;
width: 100%;
margin-top: 64px;
background: url(../images/navHeader.png) no-repeat top;
position: relative
}
nav .main-nav > ul {
list-style-type: none;
}
nav .main-nav ul a,
nav .main-nav ul li {
display: inline-block;
padding: 5px;
height: 80px;
margin: 5px;
align-content:center;
}
nav .main-nav .dropdown-content a {
height: auto;
line-height: initial;
padding: 5px 0;
}
nav .main-nav ul a {
text-align: center;
font-weight: 700;
font-size: 15px;
color: #84827d;
text-shadow: 1px 1px 1px #000;
text-transform: uppercase;
-webkit-transition: all .2s ease-in-out;
transition: all .2s ease-in-out
}
nav .main-nav ul a:hover {
text-decoration: none;
color: #7289da
}
nav .main-nav li .dropdown {
}
nav .main-nav .dropdown-content {
position: absolute;
display: none;
z-index: 10;
-webkit-box-shadow: 0 3px 5px 0 #999;
-moz-box-shadow: 0 3px 5px 0 #999;
box-shadow: 0 3px 5px 0 #999;
border: 1px solid #CCC;
background: #0d2638;
color: #656161;
opacity: .8;
top: 50px;
}
nav .main-nav .dropdown-content a {
font-size: 8px;
text-decoration: none;
display: block;
text-align: center;
}
nav .main-nav .dropdown-content a:hover {
background-color: #3A4FC5
}
nav .main-nav .dropdown:hover .dropdown-content {
display: inline-block;
}
nav .main-nav ul.left {
float: left;
margin-left: 5px;
}
.dropdown-content ul {
padding: 0;
width: auto !important;
display: flex;
flex-direction: column;
}
.dropdown-content ul li {
height: auto !important;
position: relative;
}
.dropdown-content ul li:hover > .dropdown-content-second {
display: block;
}
.dropdown-content-second {
position: absolute;
display: none;
float: left;
z-index: 10;
-webkit-box-shadow: 0 3px 5px 0 #999;
-moz-box-shadow: 0 3px 5px 0 #999;
box-shadow: 0 3px 5px 0 #999;
border: 1px solid #CCC;
background: #0d2638;
color: #656161;
opacity: .8;
min-width: 30px;
top: 0px;
margin-top: -1px;
margin-left: 1px;
left: 100%;
}
.dropdown-content-second ul li {
position: relative;
}
nav .main-nav ul.right {
float: right;
margin-right: 25px;
}
Here is my html, thank you in advance. I've been picking my brains out to figure out why but i cant seem to manage. please help.
<nav>
<div class="main-nav">
<ul class="left">
<li>Home</li>
<li class="dropdown"> Gods
<div class="dropdown-content">
<ul>
<li> Titans
<div class="dropdown-content-second">
<ul>
<li> Hades </li>
</ul>
</div>
</li>
</ul>
</div>
</li>
<li class="dropdown"> Goddesses
<div class="dropdown-content">
<ul>
<li> Olympians
<div class="dropdown-content-second">
<ul>
<li> Hera </li>
</ul>
</div>
</li>
<li> Other Goddesess
<div class="dropdown-content-second">
<ul>
<li> Gaera </li>
</ul>
</div>
</li>
</ul>
</div>
</li>
</ul>
<div class="play-now"></div>
<ul class="right">
<li class="dropdown"> Heroes
<div class="dropdown-content">
<ul>
<li> Achillies </li>
<li> Theseus </li>
</ul>
</div>
</li>
<li class="dropdown"> Myths
<div class="dropdown-content">
<ul>
<li> THE ADVENTURES OF PERSEUS </li>
</ul>
</div>
</li>
<li>Contact Us</li>
</ul>
</div>
</nav>
Try this CSS
nav {
padding-left: 5px
}
nav .main-nav {
height: 80px;
width: 100%;
margin-top: 64px;
background: url(../images/navHeader.png) no-repeat top;
position: relative
}
nav .main-nav > ul {
list-style-type: none;
}
nav .main-nav ul a,
nav .main-nav ul li {
display: inline-block;
padding: 5px;
height: 80px;
margin: 5px;
align-content:center;
}
nav .main-nav .dropdown-content a {
height: auto;
line-height: initial;
padding: 5px 0;
}
nav .main-nav ul a {
text-align: center;
font-weight: 700;
font-size: 15px;
color: #84827d;
text-shadow: 1px 1px 1px #000;
text-transform: uppercase;
-webkit-transition: all .2s ease-in-out;
transition: all .2s ease-in-out
}
nav .main-nav ul a:hover {
text-decoration: none;
color: #7289da
}
nav .main-nav li.dropdown {
position: relative;
}
nav .main-nav .dropdown-content {
position: absolute;
display: none;
z-index: 10;
-webkit-box-shadow: 0 3px 5px 0 #999;
-moz-box-shadow: 0 3px 5px 0 #999;
box-shadow: 0 3px 5px 0 #999;
border: 1px solid #CCC;
background: #0d2638;
color: #656161;
opacity: .8;
top : 35px;
}
nav .main-nav .dropdown-content a {
font-size: 8px;
text-decoration: none;
display: block;
text-align: center;
}
nav .main-nav .dropdown-content a:hover {
background-color: #3A4FC5
}
nav .main-nav .dropdown:hover .dropdown-content {
display: inline-block;
}
nav .main-nav ul.left {
float: left;
margin-left: 5px;
}
.dropdown-content ul {
padding: 0;
width: auto !important;
display: flex;
flex-direction: column;
}
.dropdown-content ul li {
height: auto !important;
position: relative;
}
.dropdown-content ul li:hover > .dropdown-content-second {
display: block;
}
.dropdown-content-second {
position: absolute;
display: none;
float: left;
z-index: 10;
-webkit-box-shadow: 0 3px 5px 0 #999;
-moz-box-shadow: 0 3px 5px 0 #999;
box-shadow: 0 3px 5px 0 #999;
border: 1px solid #CCC;
background: #0d2638;
color: #656161;
opacity: .8;
min-width: 30px;
top: 0px;
margin-top: -1px;
margin-left: 1px;
left: 100%;
}
.dropdown-content-second ul li {
position: relative;
}
nav .main-nav ul.right {
float: right;
margin-right: 25px;
}
I've made this navigation with CSS and now I'm trying to make it responsive using media queries, but I can't get the submenus to show properly. In responsive mode, I'd like to display the full menu with all links neatly underneath each other in one box. Would really appreciate some help!
https://jsfiddle.net/4L8ghza0/1/
HTML:
<header>
<div class="nav">
<ul>
<li>Start</li>
<li>Submenu1 <span class="arrow">▼</span>
<ul>
<li>link1</li>
<li>link2</li>
<li>link3</li>
</ul>
</li>
<li>Service</li>
<li>Events</li>
<li>Submenu2 <span class="arrow">▼</span>
<ul>
<li>link4</li>
<li>link5</li>
<li>link6</li>
</ul>
</li>
</ul>
</div>
</header>
CSS:
header {
top: 0px;
background-color: #EFE7D2;
position: fixed !important;
width: 100%;
height: 125px;
z-index: 10;
box-shadow: 0 2px 2px 0 rgba(0,0,0,0.12), 0 2px 10px 0 rgba(0,0,0,0.12);
}
.nav {
float: right;
padding: 40px 80px 0 0;
}
ul {
list-style-type: none;
}
ul li {
font-family: Arial, sans-serif;
font-size: 95%;
text-transform: uppercase;
display: inline-block;
position: relative;
float: left;
margin: 5px;
}
ul li a {
padding: 8px 10px;
display: block;
text-decoration: none;
color: #000000;
}
ul li:hover{
background: #CCB18E;
}
.nav .arrow {
font-size: 70%;
line-height: 0%;
}
ul li ul {
display: none;
position: absolute;
width: 210%;
padding: 0;
}
ul li ul li {
display: block;
text-decoration: none;
background: #CCB18E;
padding: 0px 10px;
margin: 0;
width: 100%;
}
ul li ul li:hover {
display: block;
background: #DAC7AD;
text-decoration: none;
padding: 0px 10px;
margin: 0;
width: 100%;
}
ul li:hover ul{
display:block;
visibility:visible;
}
ul ul li:hover li{
display:block;
}
.current {
background:#CCB18E;
color: #000000;
}
#menu-icon {
display: hidden;
width: 40px;
height: 40px;
background: url(https://cdn0.iconfinder.com/data/icons/social-messaging-productivity-4/128/menu-2-512.png) center;
}
a:hover#menu-icon {
border-radius: 4px 4px 0 0;
}
#media screen and (max-width: 1080px){
#menu-icon {
display: inline-block;
}
ul li ul li a {
display: block;
}
ul, ul:active {
display: none;
z-index: 1000;
position: absolute;
padding: 10px;
background: #EFE7D2;
right: 100px;
top: 60px;
width: 25%;
border: 1px #5F7B65 solid;
}
.nav:hover ul {
display: block;
}
ul li:hover ul li ul li {
display: none;
}
}
#JD26 I find it easier using flex-box. You can set .nav {display: flex; flex-direction:column;} in your media query. This should get you started. Or with block display: .nav {display: block}.
This question already has answers here:
My inline-block elements are not lining up properly
(5 answers)
Closed 6 years ago.
I'm a CSS starter and my pure CSS dropdown isn't working.
Example in this jsfiddle: https://jsfiddle.net/uevewfsy/
I've been looking around on internet and trying to fix it myself but I have tried countless things and it still isn't fixed. Having a float: left; on the primary ul seems to fix it, but then my nav isn't centered anymore.
Hope someone can help me so I can go further with programming again ;)
* {
padding: 0;
margin: 0;
border: 0;
}
html, body {
height: 100%;
width: 100%;
font-family: 'Open Sans', sans-serif;
}
h1 {
font-weight: 100;
}
.nav {
width: 100%;
height: 10%;
background-color: #333;
text-align: center;
position: fixed;
z-index: 150;
}
.nav ul {
height: 100%;
width: 100%;
}
.nav > ul > li {
display: inline-block;
list-style: none;
margin: 0 20px 0 20px;
}
.nav > ul > li:first-child > a:after {
width: 6px;
height: 6px;
border-bottom: 1px solid white;
border-right: 1px solid white;
position: absolute;
margin-top: calc(5vh - 5px);
margin-left: 8px;
content: "";
transform: rotate(45deg);
}
.nav > ul > li > ul {
display: none;
}
.nav > ul > li > ul > li {
list-style: none;
background-color: #333;
padding: 0 15px 0 15px;
}
.nav li:hover > ul {
display: block;
}
.nav ul a {
color: #A3ABA3;
text-decoration: none;
line-height: 10vh;
}
.nav a:hover {
color: #FFF;
}
#media only screen and (max-device-width: 480px){
}
<body>
<div class="nav">
<ul>
<li>
PAGE
<ul>
<li>DROPDOWN</li>
<li>DROPDOWN</li>
</ul>
</li>
<li>PAGE</li>
<li>PAGE</li>
<li>PAGE</li>
</ul>
</div>
</body>
you are just missing vertical-align:top in your nav > ul > li,
you can add position:relative/top to your li/ul as well.
* {
padding: 0;
margin: 0;
border: 0;
}
html,
body {
height: 100%;
width: 100%;
font-family: 'Open Sans', sans-serif;
}
h1 {
font-weight: 100;
}
.nav {
width: 100%;
height: 10%;
background-color: #333;
text-align: center;
position: fixed;
z-index: 150;
}
.nav ul {
height: 100%;
width: 100%;
}
.nav > ul > li {
display: inline-block;
list-style: none;
padding: 0 20px;
vertical-align: top
}
.nav > ul > li:first-child > a:after {
width: 6px;
height: 6px;
border-bottom: 1px solid white;
border-right: 1px solid white;
position: absolute;
margin-top: calc(5vh - 5px);
margin-left: 8px;
content: "";
transform: rotate(45deg);
}
.nav > ul > li > ul {
display: none;
}
.nav > ul > li > ul > li {
list-style: none;
background-color: #333;
padding: 0 15px;
position:relative
}
.nav li:hover > ul {
display: block;
position:absolute;
top:100%;
width:30%
}
.nav ul a {
color: #A3ABA3;
text-decoration: none;
line-height: 10vh;
}
.nav a:hover {
color: #FFF;
}
#media only screen and (max-device-width: 480px) {}
<body>
<div class="nav">
<ul>
<li>
PAGE
<ul>
<li>DROPDOWN
</li>
<li>DROPDOWN
</li>
</ul>
</li>
<li>PAGE
</li>
<li>PAGE
</li>
<li>PAGE
</li>
</ul>
</div>
</body>
I have a CSS menu with submenu. At the top level, there is a border for top, left, and right. For the submenu, there is a border on all 4 sides. See the JSFiddle at https://jsfiddle.net/vjy8adff/.
I want to move the submenu up by 1px to create an effect that there is only one loop around the parent tab and submenu. Since my submenu is now "absolute" positioned, I can't do the following:
ul ul{
top: -1px;
}
What is the best solution here.
At line 17 add :
margin-top: -1px;
Full code :
ul.menu > li > ul {
width: auto;
margin-top: -1px;
display: none;
position: absolute;
white-space: nowrap;
background-color: #fff;
padding: 10px;
border-radius: 2px;
}
if you set top to -1px the element will calculate the top right from the top i have set the top to 100% which will bring the element down to 100% and removed 1px from it which is the border
top:calc(100% - 1px);
so that it takes the element to 100% below and exclude 1px border
you can also use #ianis solution where the element is moved 1px top with -ve margin it acts like position:relative with -ve top value
ul.no-style {
list-style: none;
margin: 0;
padding: 0;
}
ul.no-style li {
padding: 0;
}
ul.list-inline > li {
display: inline-block;
}
/* basic menu structure */
ul.menu > li {
padding-right: 15px;
position: relative;
width: 50px;
}
ul.menu > li > ul {
width: auto;
display: none;
position: absolute;
white-space: nowrap;
background-color: #fff;
padding: 10px;
margin-top: -1px;
border-radius: 2px;
}
ul.menu > li > div.multi-2col {
display: none;
position: absolute;
width: 180px;
white-space: nowrap;
background-color: #fff;
border: solid #eee 1px;
border-radius: 2px;
}
ul.menu > li > div.multi-2col div.multi-2a {
padding-right: 15px;
}
ul.menu > li > div.multi-2col div.multi-2a,
ul.menu > li > div.multi-2col div.multi-2b {
padding: 10px;
width: auto;
float: left;
}
ul.menu > li > div.multi-2col.right {
right: 0;
}
ul.menu > li > div.multi-2col.right .multi-2a {
padding-left: 15px;
}
ul.menu > li > div.multi-2col.right .multi-2a,
ul.menu > li > div.multi-2col.right .multi-2b {
width: auto;
float: right;
}
ul.menu > li:last-child {
padding-right: 0px;
}
ul.menu > li:hover ul,
ul.menu > li:hover div.multi-2col {
display: block;
}
/* border wrap submenu and parent */
ul.menu.border-wrap > li {
padding: 0px;
border-top: 1px solid transparent;
border-left: 1px solid transparent;
border-right: 1px solid transparent;
}
ul.menu.border-wrap > li > a {
position: relative;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 5px;
padding-right: 5px;
display: block;
background-color: #eee;
}
ul.menu.border-wrap > li:hover {
background-color: #eee;
border-top: solid red 1px;
border-left: solid red 1px;
border-right: solid red 1px;
}
ul.menu.border-wrap > li:hover a {
z-index: 5;
}
ul.menu.border-wrap > li:hover > ul,
ul.menu.border-wrap > li:hover > div.multi-2col {
background-color: #eee;
border: solid red 1px;
left: -1px;
z-index: 2;
}
<ul class="no-style list-inline menu border-wrap">
<li>
Home
<ul class="no-style">
<li>Sub Item</li>
<li>Sub Item</li>
<li>Sub Item</li>
<li>Sub Item</li>
</ul>
</li>
</ul>
I am using the CSS :before pseudo-selector to create a block above the first item in a drop down list. I've been having trouble getting this block created with the pseudo-selector to be the same width as the <li> above it.
For example when you hover over "About" the pseudo block that appears beneath it should be the same width as the block that contains the word "About" and so on for the other 3 blocks.
Here's a fiddle to what I have got so far: http://jsfiddle.net/jh67P/
Here's my HTML:
<nav>
<ul class="main">
<li>About
<ul class="secondary">
<li>Learn About Us</li>
<li>Nice things to know</li>
</ul>
</li>
<li>Products
<ul class="secondary">
<li>Product One</li>
<li>Product Two</li>
</ul>
</li>
<li>Features
<ul class="secondary">
<li>Something Nice</li>
<li>Another nice thing</li>
</ul>
</li>
</ul>
</nav>
Here's the CSS:
nav .main {
font-size: 1em;
margin: 0;
padding: 0;
list-style: none;
}
.main > li {
display: block;
position: relative;
float: left;
}
.main > li a {
display: block;
text-decoration: none;
color:#FFF;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #1e7c9a;
margin-left: 1px;
white-space: nowrap;
}
.main > li a:hover {
background: #3b3b3b;
color:#FFF;
}
.secondary {
display:none;
list-style: none;
margin: 0;
padding: 0;
}
.main li:hover .secondary {
display: block;
position: absolute;
}
.main li:hover ul li {
float: none;
font-size: 1em;
}
.main > li:hover a { background: #3b3b3b; }
.main > li:hover li a:hover {
background: #1e7c9a;
}
.main li:hover ul:before {
content:'';
display:block;
width:100%;
height:10px;
border-bottom:10px solid #1e7c9a;
border-right: 10px solid transparent;
}
Edit: Using absolute positioning I was able to achieve the effect. Here's the updated CSS.
nav .main {
font-size: 1em;
margin: 0;
padding: 0;
list-style: none;
}
.main > li {
display: block;
position: relative;
float: left;
}
.main > li a {
display: block;
text-decoration: none;
color:#FFF;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #1e7c9a;
margin-left: 1px;
white-space: nowrap;
}
.main > li a:hover {
background: #3b3b3b;
color:#FFF;
}
.secondary {
display:none;
list-style: none;
margin: 0;
padding: 0;
}
.main li:hover .secondary {
display: block;
position: absolute;
top:40px;
}
.main li:hover ul li {
float: none;
font-size: 1em;
}
.main > li:hover a { background: #3b3b3b; }
.main > li:hover li a:hover {
background: #1e7c9a;
}
.main > li:hover:after {
content:'';
display:block;
width:100%;
height:10px;
border-bottom:10px solid #1e7c9a;
border-right: 10px solid transparent;
position:absolute;
top:20px;
margin-left:1px;
}
How about changing:
.main li:hover ul:before {
To:
.main > li:hover > a:after {
Is that what you are after?
jsFiddle