I am trying to create a drop down menu similar to the one found on this website http://yachtbelleaimee.com/
I have created the drop down menu however I do not know how to position the lists like that found in the website. And like the website I would also like to known how to position the list below the header. Thank you very much for any help you can provide
/* NAVIGATION START */
nav {
display: block;
width: 960px;
margin: 100px auto;
text-align: center;
}
nav select {
display: none;
}
#menu {
width: 608px;
margin-top: 0px;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
}
#menu ul {
margin: 0px;
padding: 0px;
}
#menu ul li {
background-color: #666;
float: left;
border: 1px solid #CCC;
position: relative;
list-style-type: none;
}
#menu ul li:hover ul {
visibility: visible;
background-color: #333;
}
#menu ul li a {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 14px;
line-height: 30px;
color: #FFF;
text-decoration: none;
text-align: center;
display: block;
height: 30px;
width: 150px;
}
#menu ul ul {
position: absolute;
visibility: hidden;
left: -1px;
top: 31px;
}
#menu ul li:hover {
background-color: #333;
}
#menu ul li ul li a:hover {
background-color: #069;
}
#menu ul li a:hover {
color: #0FF;
}
#leftmenu {
position: absolute;
left: 165px;
top: 20px;
}
#rightmenu {
position: absolute;
right: 164px;
top: 20px;
}
/* NAVIGATION END */
<nav>
<div id="menu">
<ul id='leftmenu'>
<li>BOAT
<ul>
<li><a href='#'>Specs & Boat Plans</a></li>
<li><a href='#'>Itineraries</a></li>
<li><a href='#'>Exteriors</a></li>
<li><a href='#'>Diving & Water Toys</a></li>
</ul>
</li>
</ul>
<ul id='rightmenu'>
<li>LIFE ON BOARD
<ul>
<li><a href='#'>Itineraries</a></li>
<li><a href='#'>Dining</a></li>
<li><a href='#'>Family Fun</a></li>
<li>Lifelong Learning</li>
<li>The Crew</li>
</ul>
</li>
</ul>
</div>
</nav>
Here's some CSS to get you started:
/* NAVIGATION START */
nav {
display: block;
width: 960px;
margin: 100px auto;
text-align: center;
}
nav select {
display: none;
}
#menu {
width: 608px;
margin-top: 0px;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
}
#menu ul {
margin: 0px;
padding: 0px;
}
#menu ul li {
background-color: #666;
float: left;
border: 1px solid #CCC;
position: relative;
list-style-type: none;
}
#menu ul li:hover ul {
visibility: visible;
}
#menu ul li a {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 14px;
line-height: 30px;
color: #FFF;
text-decoration: none;
text-align: center;
display: block;
height: 30px;
width: 150px;
}
#menu ul ul {
position: absolute;
visibility: hidden;
left: -1px;
top: 31px;
}
#menu ul li:hover {
background-color: #333;
}
#menu ul li ul li a:hover {
background-color: #069;
}
#menu ul li a:hover {
color: #0FF;
}
#leftmenu {
position: absolute;
left: 165px;
top: 20px;
}
#leftmenu li>ul>li {
margin:1em 0;
}
#leftmenu li:nth-child(2) {
margin-left:20px;
}
#leftmenu li:nth-child(3) {
margin-left:40px;
}
#leftmenu li:nth-child(4) {
margin-left:60px;
}
#rightmenu {
position: absolute;
right: 164px;
top: 20px;
}
#rightmenu li>ul>li {
margin:1em 0;
}
#rightmenu li:nth-child(2) {
margin-left:-20px;
}
#rightmenu li:nth-child(3) {
margin-left:-40px;
}
#rightmenu li:nth-child(4) {
margin-left:-60px;
}
#rightmenu li:nth-child(5) {
margin-left:-80px;
}
And a JSFiddle.
You can simplify
#menu {
width: 608px;
margin-top: 0px;
margin-right: auto;
margin-bottom: 0px;
margin-left: auto;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
}
to
#menu {
width: 608px;
margin: 0px auto;
padding: 0px;
}
For that... er... cascading effect, you'll probably have to use something like
<li style="padding-left: some value here">
and decrease it with each <li> (since you're floating them right). Also, the menu will have to be as wide as the space that goes from the leftmost menu item to the rightmost; it cannot be as wide as one menu item.
Related
I know others have asked this question and I'm not able to wrap my head around those solutions due to the complexity of the CSS being used and I have submenus within. This was made by an online menu CSS generator. This is the page that I'm building:
http://sandboxisle.com/home-page-main/
#menu {
background: #00338D;
color: #FFF;
height: 45px;
padding-left: 18px;
border-radius: 10px;
}
#menu ul, #menu li {
margin: 0 auto;
padding: 0;
list-style: none;
}
#menu ul {
width: 100%;
}
#menu li {
float: left;
display: inline;
position: relative;
}
#menu a {
display: block;
line-height: 45px;
padding: 0 14px;
text-decoration: none;
color: #EBB700;
font-size: 16px;
}
#menu a.dropdown-arrow:after {
content: "\25BE";
margin-left: 5px;
}
#menu li a:hover {
color: #FFFFFF;
background: #00338D;
}
#menu input {
display: none;
margin: 0;
padding: 0;
height: 45px;
width: 100%;
opacity: 0;
cursor: pointer
}
#menu label {
display: none;
line-height: 45px;
text-align: center;
position: absolute;
left: 35px
}
#menu label:before {
font-size: 1.6em;
content: "\2261";
margin-left: 20px;
}
#menu ul.sub-menus{
height: auto;
overflow: hidden;
width: 250px;
background: #766A62;
position: absolute;
z-index: 99;
display: none;
}
#menu ul.sub-menus li {
display: block;
width: 100%;
}
#menu ul.sub-menus a {
color: #EBB700;
font-size: 16px;
}
#menu li:hover ul.sub-menus {
display: block
}
#menu ul.sub-menus a:hover{
background: #766A62;
color: #ffffff;
}
#media screen and (max-width: 800px){
#menu {position:relative}
#menu ul {background:#766A62;position:absolute;top:100%;right:0;left:0;z-index:3;height:auto;display:none}
#menu ul.sub-menus {width:100%;position:static;}
#menu ul.sub-menus a {padding-left:30px;}
#menu li {display:block;float:none;width:auto;}
#menu input, #menu label {position:absolute;top:0;left:0;display:block}
#menu input {z-index:4}
#menu input:checked + label {color:white}
#menu input:checked + label:before {content:"\00d7"}
#menu input:checked ~ ul {display:block}
}
Here's my HTML
<nav id='menu'>
<input type='checkbox' id='responsive-menu' onclick='updatemenu()'><label></label>
<ul>
<li><a href='Calendar'>Calendar</a></li>
<li><a href='News'>News</a></li>
<li><a class='dropdown-arrow' href='For Members'>For Members</a>
<ul class='sub-menus'>
<li><a href='Orientation'>Orientation</a></li>
<li><a href='Leadership Building'>Leadership Building</a></li>
<li><a href='Newsletters'>Newsletters</a></li>
</ul>
</li>
<li><a class='dropdown-arrow' href='Resource'>Resource</a>
<ul class='sub-menus'>
<li><a href='Service Documents'>Service Documents</a></li>
<li><a href='District 50 Clubs Directory'>District 50 Clubs Directory</a></li>
<li><a href='Awards & Contests'>Awards & Contests</a></li>
<li><a href='D50 Resource'>D50 Resource</a></li>
<li><a href='Club Resource'>Club Resource</a></li>
<li><a href='LCIF Resource'>LCIF Resource</a></li>
</ul>
</li>
</ul>
</nav>
Please check the code below:
#menu {
background: #00338d;
color: #fff;
height: 45px;
padding-left: 18px;
border-radius: 10px;
}
#menu ul {
margin: 0;
padding: 0;
}
#menu li {
padding: 0;
list-style: none;
}
#menu .navbar {
display: flex;
justify-content: end;
width: 1170px;
margin: 0 auto;
}
#menu li {
float: left;
display: inline;
position: relative;
}
#menu a {
display: block;
line-height: 45px;
padding: 0 14px;
text-decoration: none;
color: #ebb700;
font-size: 16px;
}
#menu a.dropdown-arrow:after {
content: "\25BE";
margin-left: 5px;
}
#menu li a:hover {
color: #ffffff;
background: #00338d;
}
#menu input {
display: none;
margin: 0;
padding: 0;
height: 45px;
width: 100%;
opacity: 0;
cursor: pointer;
}
#menu label {
display: none;
line-height: 45px;
text-align: center;
position: absolute;
left: 35px;
}
#menu label:before {
font-size: 1.6em;
content: "\2261";
margin-left: 20px;
}
#menu ul.sub-menus {
height: auto;
overflow: hidden;
width: 250px;
background: #766a62;
position: absolute;
z-index: 99;
display: none;
}
#menu ul.sub-menus li {
display: block;
width: 100%;
}
#menu ul.sub-menus a {
color: #ebb700;
font-size: 16px;
}
#menu li:hover ul.sub-menus {
display: block;
}
#menu ul.sub-menus a:hover {
background: #766a62;
color: #ffffff;
}
#media screen and (max-width: 800px) {
#menu {
position: relative;
}
#menu ul {
background: #766a62;
position: absolute;
top: 100%;
right: 0;
left: 0;
z-index: 3;
height: auto;
display: none;
}
#menu ul.sub-menus {
width: 100%;
position: static;
}
#menu ul.sub-menus a {
padding-left: 30px;
}
#menu li {
display: block;
float: none;
width: auto;
}
#menu input,
#menu label {
position: absolute;
top: 0;
left: 0;
display: block;
}
#menu input {
z-index: 4;
}
#menu input:checked + label {
color: white;
}
#menu input:checked + label:before {
content: "\00d7";
}
#menu input:checked ~ ul {
display: block;
}
}
<nav id="menu">
<input
type="checkbox"
id="responsive-menu"
onclick="updatemenu()"
/><label></label>
<ul class="navbar">
<li>Calendar</li>
<li>News</li>
<li>
<a class="dropdown-arrow" href="For Members">For Members</a>
<ul class="sub-menus">
<li>Orientation</li>
<li>Leadership Building</li>
<li>Newsletters</li>
</ul>
</li>
<li>
<a class="dropdown-arrow" href="Resource">Resource</a>
<ul class="sub-menus">
<li>Service Documents</li>
<li>
<a href="District 50 Clubs Directory"
>District 50 Clubs Directory</a
>
</li>
<li>Awards & Contests</li>
<li>D50 Resource</li>
<li>Club Resource</li>
<li>LCIF Resource</li>
</ul>
</li>
</ul>
</nav>
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}.
I want to create a horizontal menu, which starts right on the top of the page, meaning I do not want to be any margin above it, but I do not know how to do that. I tried with top: 0; margin:auto;, but it does not work... my CSS code is right here:
.menu1
{
position: absolute;
top: 0;
margin:auto;
left: 0;
right: 0;
width: 100%;
}
.menu1 ul
{
list-style-type: none;
padding: 0;
overflow: hidden;
height: 30px;
background-color: purple;
}
.menu1 li
{
float:left;
margin-right: 10px;
}
.menu1 li a
{
display: block;
color: white;
text-align: center;
padding: 8px 10px;
text-decoration: none;
}
.menu1 li a:hover
{
text-decoration: underline;
}
Add margin:0; in .menu1 ul
and everything will be fine.
See the code below
thanks
.menu1
{
position: absolute;
top: 0;
margin:auto;
left: 0;
right: 0;
width: 100%;
}
.menu1 ul
{
list-style-type: none;
padding: 0;
overflow: hidden;
height: 30px;
background-color: purple;
margin:0;
}
.menu1 li
{
float:left;
margin-right: 10px;
}
.menu1 li a
{
display: block;
color: white;
text-align: center;
padding: 8px 10px;
text-decoration: none;
}
.menu1 li a:hover
{
text-decoration: underline;
}
<div class="menu1">
<ul>
<li>one</li>
<li>one</li>
<li>one</li>
<li>one</li>
</ul>
</div>
body, html, .menu { margin:0 auto; }
Add in style may it helps you
*{margin:0px 0px; padding:0px 0px;}
You have two options.
1: *{margin:0px 0px; padding:0px 0px;}
2: Use Reset CSS
I created a css drop down menu and i am finishing it up with a border. When i added the left and bottom border everything was fine. Once i added the right border it put a gap between the right border and the drop down menu. Is there anyway to fix this?
Here is a photo http://sphotos-b.ak.fbcdn.net/hphotos-ak-ash3/563034_641717089180441_1749213926_n.jpg
The HTML I Used:
<nav id="main_nav" class="fluid">
<ul>
<li>Home</li>
<li>Show Services
<ul>
<li>Audio</li>
<li>Lighting</li>
<li>Power</li>
<li>Special Effects</li>
<li>Staging/Trussing</li>
<li>Video</li>
</ul>
</li>
<li>Systems Integration
<ul>
<li>Corporate and Commercial</li>
<li>Digital Signage</li>
<li>Entertainment</li>
<li>IP Based Systems</li>
</ul>
</li>
<li>Portfolio
<ul>
<li>Concrets</li>
<li>Installations</li>
<li>Parties</li>
<li>Product Launch</li>
<li>Trade Shows</li>
</ul>
</li>
<li>Our Company</li>
</ul>
</nav>
The CSS I Used:
#main_nav {
}
#main_nav ul {
list-style-type: none;
margin-top: 0%;
margin-right: 0%;
margin-bottom: 0%;
margin-left: 0%;
padding-top: 0%;
padding-right: 0%;
padding-bottom: 0%;
padding-left: 0%;
width: 100%;
position: relative;
float: left;
}
#main_nav ul li {
float: left;
position: relative;
width: 20%;
margin-top: 0%;
margin-right: 0%;
margin-bottom: 0%;
margin-left: 0%;
padding-top: 0%;
padding-right: 0%;
padding-bottom: 0%;
padding-left: 0%;
background-color: #4d4d4d;
}
#main_nav ul li a {
width: 100%;
float: left;
text-align: center;
text-transform: uppercase;
color: #FFFFFF;
text-decoration: none;
padding-top: 0%;
font-style: normal;
font-weight: 400;
font-family: allerta;
font-size: 1em;
display: block;
padding-right: 0%;
padding-bottom: 0%;
padding-left: 0%;
margin-top: 0%;
margin-right: 0%;
margin-bottom: 0%;
margin-left: 0%;
border-left: 0.1em solid #999999;
border-bottom: 0.1em solid #999999;
border-right: 0.1em solid #999999;
}
#main_nav a:hover, #main_nav a:active, #main_nav a:focus, #main_nav a.thispage {
background-color: #666666;
color: #0099FF;
width: 100%;
}
#main_nav ul li ul {
visibility: hidden;
margin-right: 0%;
margin-bottom: 0%;
margin-left: 0%;
padding-right: 0%;
padding-bottom: 0%;
padding-left: 0%;
float: left;
list-style-type: none;
position: absolute;
margin-top: 100%;
padding-top: 0%;
width: 100%;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
}
#main_nav ul li ul li {
position: relative;
float: left;
width: 100%;
margin-top: 0%;
margin-right: 0%;
margin-bottom: 0%;
margin-left: 0%;
padding-top: 0%;
padding-right: 0%;
padding-bottom: 0%;
padding-left: 0%;
background-color: #4d4d4d;
}
#main_nav ul li ul li a {
width: 100%;
padding-right: 0%;
padding-bottom: 0%;
padding-left: 0%;
margin-top: 0%;
margin-right: 0px;
margin-bottom: 0px;
margin-left: 0px;
padding-top: 0%;
float: left;
font-style: normal;
font-weight: 400;
font-family: allerta;
font-size: 0.9em;
text-align: center;
text-decoration: none;
display: block;
color: #FFFFFF;
text-transform: uppercase;
}
#main_nav ul li:hover ul, #main_nav ul li:active ul, #main_nav ul li:focus ul, #main_nav ul li.thispage ul {
visibility: visible;
width: 100%;
}
I took a look at your code and have made some changes. Also took the liberty of creating a JS Fiddle example for you. I haven't changed any HTML, only the CSS.
See JS Fiddle here
html {
font: 100%/1.5 Arial, Helvetica, sans-serif;
}
html, body {
margin: 0;
}
/* Common (Shared) Properties */
#main_nav, ul, li, a {
display: block;
margin: 0;
padding: 0;
}
#main_nav ul {
list-style: none;
width: 100%;
position: relative;
float: left;
}
#main_nav li {
float: left;
position: relative;
width: 20%;
background: #4d4d4d;
}
#main_nav a {
float: none;
text-align: center;
text-transform: uppercase;
color: #FFF;
text-decoration: none;
font-size: 1em;
border: 1px solid #999;
border-top: none;
}
#main_nav a:hover,
#main_nav a:active,
#main_nav a:focus,
#main_nav a.thispage {
background: #666;
color: #FFF;
}
/* Controls Dropdown */
#main_nav ul li ul {
visibility: hidden;
position: absolute;
top: auto; /* Updated position to 'auto' and removed margin-top: 100% */
left: 0;
}
#main_nav ul ul li {
float: none;
width: 100%;
}
#main_nav ul li:hover ul,
#main_nav ul li:active ul,
#main_nav ul li:focus ul,
#main_nav ul li.thispage ul {
visibility: visible;
display: block;
}
I rewrote CSS which hopefully will be helpful to learn from as it is much simpler to understand as well as it fixes your problem.
Problem was that the sub menu items were with 100% width + 1px border on each side which is over 100% so it was overflowing.
Here is the link to JS Fiddle example with fix: http://jsfiddle.net/MartinTale/69gDQ/3/
Here is the new css:
#main_nav ul {
list-style-type: none;
margin: 0;
padding: 0;
}
#main_nav ul {
width: 100%;
}
#main_nav li {
background-color: #4d4d4d;
margin: 0;
padding: 0;
text-align: center;
width: 100%;
}
#main_nav > ul > li {
float: left;
width: 20%;
}
#main_nav ul ul {
display: none;
}
#main_nav ul li:hover ul {
display: inline-block;
}
#main_nav a {
text-align: center;
text-decoration: none;
color: #FFF;
text-transform: uppercase;
display: inline-block;
width: 100%;
border-left: 1px solid #999999;
border-bottom: 1px solid #999999;
border-right: 1px solid #999999;
}
#main_nav ul li ul a {
border-left: 0;
border-right: 0;
}
#main_nav a:hover,
#main_nav a:active,
#main_nav a:focus,
#main_nav a.thispage {
background: #666;
color: #09F;
}
SEE LIVE MENU HERE.
I am trying to figure out why the drop-down disappears after you attempt to rollover it. Can someone see the problem in my code? Thank you.
HERE IS MY HTML MENU
<div id="menu">
<ul>
<li><span>Needs Assessment</span> </li>
<li><span>Knowledge Acquisition</span>
<ul>
<li>Administer Knowledge<br>Pre-Test</li>
<li>Assign Asthma<br>Article </li>
<li>Administer Knowledge<br>Post-Test</li>
<li>Discuss Asthma<br>Case Study</li>
</ul>
</li>
<li><span>Skills Proficiency</span> </li>
<li><span>Simulation in Teams</span>
<ul>
<li>Perform Asthma<br>Simulation</li>
<li>Facilitate<br>Debriefing</li>
</ul>
</li>
<li><span>Performance</span></li>
<li><span>Resources</span></li>
</ul>
</div>
HERE IS MY CSS
#menu {
position: relative;
top: 10px;
left: 0px;
width: 940px;
height: 47px;
}
#menu ul {
position: relative;
top: -15px;
left: 0px;
margin-left: 0px;
padding-left: 0px;
list-style: none;
}
#menu ul li {
position: relative;
display: inline;
float: left;
list-style: none;
margin-right: 0px;
border: solid 0px #4981a8;
width: 156px;
background-image: url ('http://www.laerdal.com/Laerdal/usa/discoversimulation/images/button.png');
background-repeat: no-repeat;
}
#menu ul li a {
display: block;
width: 156px;
padding: 12px 0px 10px 0px;
border: solid 0px #fff;
font-family: 'Cabin', sans-serif;
font-size: 14px;
font-weight: lighter;
text-align: center;
text-decoration: none;
}
#menu a span {
float: left;
display: block;
padding: 3px 5px 4px 6px;
color:#fff;
float: none;
}
#menu a:hover span {
color:#ffdd00;
}
#menu li ul {
position: absolute;
top: 47px;
left: 0px;
background-color:#4981a8;
border: solid 1px #4981a8;
display: none;
}
#menu li:hover ul {
display: block;
z-index: 999;
}
#menu li li a {
font-family: 'Cabin', sans-serif;
font-size: 14px;
color: #000;
font-weight: lighter;
height: 38px;
background-color:#eee;
margin-bottom: -9px;
}
#menu li li a:hover {
color: #065389;
}
You have another element on your page that's partially covering up the navigation:
#textbox {
position: relative;
top: -30px;
}
This is blocking the :hover. To solve this, give your #header a z-index:1. Any positive value should work, you just need to set it to something so the element stays on top.