I really don't know what should be the correct title for this question, but I have a custom menu I have created and using JQuery to toggle, it looks like this.
<ul class="menu">
<li class="user-info">
<span class="fa fa-user"></span>
<a class="inline" href="https://example.com/">account</a>
<ul class="items">
<li class="item">
<span class="fa fa-lock"></span>
<a class="inline" href="https://example.com/register">Create Account</a>
</li>
<li class="item">
<span class="fa fa-login"></span>
<a class="inline" href="https://example.com/login">Account Login</a>
</li>
</ul>
</li>
</ul>
And here is my CSS code
ul, ul li, ol, ol li {
display: block;
margin: 0;
padding: 0;
list-style: none;
}
#media (max-width: 540px) {
#sidebar ul.menu {
height: auto!important;
}
}
#sidebar .menu {
height: calc(100vh - 94px);
overflow: auto;
transition: 200ms ease-out height;
}
#media (max-width: 540px) {
#sidebar ul.menu li {
width: 20%;
float: left;
margin: 0!important;
text-align: center;
padding: 10px 5px;
z-index: 111;
height: 50px;
}
}
#sidebar ul li {
font-weight: 400;
font-size: 10pt;
text-transform: capitalize;
position: relative;
cursor: pointer;
}
#media (max-width: 540px) {
#sidebar ul.menu li ul {
background: #222629;
border-bottom: 1px solid rgb(255 255 255 / 08%);
right: 0;
left: 0;
bottom: 50px;
top: 0;
position: fixed!important;
display: block;
opacity: 0;
visibility: hidden;
transition: 200ms ease-in all;
overflow: auto;
width: 100%;
box-shadow: none;
}
}
#sidebar ul.menu li ul {
background: #222629;
}
#media (max-width: 540px) {
#sidebar ul.menu li.shown ul {
opacity: 1;
visibility: visible;
display: block!important;
}
}
So far everything works well on all platforms except iOS although, I haven't tried on MAC, but I've tested across over 5 iOS devices including iOS 14.1 but the menu wont toggle when the .shown class is appended to the li.user-info item.
What am I doing wrongly?
EDIT:
I have updated my css to include this at the top:
#sidebar ul.menu li.shown ul {
opacity: 0;
visibility: hidden;
display: none;
}
Still doesn't work, I have also set opacity:1 and visibility:visible and display:block in the above piece of code, still, nothing worked.
Update: There is no element with a .menu_wrapper class, there was a typo, I mistakenley copied css from my old code for this question, I had to come up with simpler naming conventions to aid debugging.
Related
I am writing a navigation bar with a dropdown option.
I have 2 problems: I can't get the dropdown to position properly under the menu, + also when I try to move the mouse to click on the elements in the dropdown submenu it closes as soon as I move.
Can anyone suggest a fix?
Thanks
On codepen:
https://codepen.io/-royqooe/pen/GRxaVbm
/* CSS section for home */
.navtop {
position: relative;
background-color: #333333;
height: 50px;
width: 100%;
border: 0;
}
.navtop div {
display: flex;
margin: 0 auto;
height: 100%;
}
.navtop div h1,
.navtop div a {
display: inline-flex;
align-items: center;
}
.navtop div h1 {
flex: 1;
font-size: 24px;
padding: 0;
margin: 0;
margin-left: 2%;
color: #f5f8ff;
font-weight: normal;
}
.navtop div a {
padding: 0 12px;
text-decoration: none;
color: #c1c4c8;
font-weight: bold;
}
.navtop div a i {
padding: 2px 8px 0 0;
}
.navtop div a:hover {
color: #66ccff;
}
/* sequel for home and navbar */
nav.navtop {
font-family: monospace;
}
.navtop>.navbar>ul {
list-style: none;
margin: 0;
padding-left: 0;
}
.navtop li {
display: block;
float: left;
padding: 0.5rem 0;
position: relative;
text-decoration: none;
transition-duration: 0.3s;
}
.navtop ul li ul {
background: red;
visibility: hidden;
opacity: 0;
min-width: 5rem;
position: absolute;
transition: all 0.5s ease;
margin-top: 1rem;
left: 0;
display: none;
}
.navtop ul li:hover>ul,
.navtop ul li ul:hover {
visibility: visible;
opacity: 1;
display: block;
}
.navtop ul li ul li {
clear: both;
width: 100%;
}
#media screen and (max-width: 760px) {
.topbar-text {
display: none;
}
}
<nav class="navlol navtop" role="navigation">
<div class="navbar">
<h1>Websitee Title</h1>
<ul>
<li><i class="fa-solid fa-file"></i><span class="topbar-text">Home</span></li>
<li>Two
<ul class="dropdownnn">
<li>Sub-1</li>
<li>Sub-2</li>
<li>Sub-3</li>
</ul>
</li>
<li class="navelements">Three</li>
<li><i class="fas fa-user-circle"></i><span class="topbar-text">Profile</span></li>
<li><i class="fas fa-sign-out-alt"></i><span class="topbar-text">Logout</span></li>
</ul>
</div>
</nav>
got an easy fix for you:
add this
.navtop li {
min-height:25px;
}
the issue is that that menu li was way shorter than the others to the sides due to the icons, even better maybe is instead adding this instead:
.navtop li {
height:100%
}
both worked for me
In the screenshot, the yellow color is the area that <li> element is covering. You can see there is a gap between <li> element and submenu. When you try to move the mouse to submenu, your cursor goes out of yellow area and the submenu hides.
The solution would be to position the submenu so it starts exactly after yellow area and make sure there is no gap. Apply margin-top of 0.5rem on submenu instead of 1rem.
I am trying to implement the step progress bar and I have done the below for the desktop version.
Photo who works on the desktop like
Desktop Version
When I try to do it horizontally on a mobile that does not work, it appears vertically
Photo who works in the mobile
Mobile Version
Code Html :
<div class="progress">
<ul1>
<li>
<i class="fa fa-check"></i>
<p>Email</p>
</li>
<li>
<i class="fa fa-refresh"></i>
<p>Register form</p>
</li>
<li>
<i class="fa fa-times"></i>
<p>Done</p>
</li>
</ul1>
</div>
CSS Code :
.progress{
margin-left: 10px auto;
}
.progress img{
width: 80px;
margin-bottom: 20px;
}
ul1{
text-align: center;
}
ul1 li{
display: inline-block;
width: 200px;
position: relative;
margin-top: 10px;
}
ul1 li .fa{
background: #ccc;
height: 26px;
color: #fff;
border-radius: 50%;
padding: 5px;
}
ul1 li .fa::after{
content: '';
background: #ccc;
height: 5px;
width: 205px;
display: block;
position: absolute;
left: 0;
top: 60px;
z-index: -1;
}
ul1 li:nth-child(2) .fa{
background: #ca261a;
}
ul1 li:nth-child(2) .fa::after{
background: #ca261a;
}
ul1 li:nth-child(1) .fa
{
background: #60aa97;
}
ul1 li:nth-child(1) .fa::after
{
background: #60aa97;
}
ul1 li:first-child .fa::after{
width: 105px;
left: 100px;
}
ul1 li:last-child .fa::after{
width: 105px;
}
You use fixed width (in px unit) while overall width from 3 li is wider than screen size.
To fix this, use fluid width such as percentage (%).
.progress {
margin-left: 10px auto;
}
.progress img {
width: 80px;
margin-bottom: 20px;
}
/* use media queries to smaller font size on small screen to prevent them push bar to vertical. */
.progress p {
font-size: 12px;
}
#media (min-width: 400px) {
.progress p {
font-size: initial;
}
}
ul {
list-style: none;
text-align: center;
}
ul li {
list-style: none;
display: inline-block;
width: 30.33%;/* make it fluid */
position: relative;
margin-top: 10px;
}
ul li .fa {
background: #ccc;
height: 26px;
color: #fff;
border-radius: 50%;
padding: 5px;
}
ul li .fa::after {
content: '';
background: #ccc;
height: 5px;
width: 100%;/* make it fluid */
display: block;
position: absolute;
left: 0;
top: 60px;
z-index: 0;/* higher than last step */
}
ul li:nth-child(2) .fa {
background: #ca261a;
}
ul li:nth-child(2) .fa::after {
background: #ca261a;
}
ul li:nth-child(1) .fa {
background: #60aa97;
}
ul li:nth-child(1) .fa::after {
background: #60aa97;
}
ul li:first-child .fa::after {
width: 100%;
left: 50%;
}
ul li:last-child .fa::after {
width: 60%;/* +10 for -10 in left property */
left: -10%;/* for remove empty space on left */
z-index: -1;/* put to bottom */
}
<div class="progress">
<ul>
<li>
<i class="fa fa-check"></i>
<p>Email</p>
</li>
<li>
<i class="fa fa-refresh"></i>
<p>Register form</p>
</li>
<li>
<i class="fa fa-times"></i>
<p>Done</p>
</li>
</ul>
</div>
I've changed your CSS a little, please read in code comment (/* comment */).
However, you may found that in very small screen the font maybe very small. This is for prevent the progress step push to new line. It is not good fix but it can be helped.
Smallest screen tested is 320pixels.
See it on jsfiddle.
I have tried to embed a vertical menu bar on my Blogger website. But it seems like it's not responsive and the colour is not matching my website.
I need to remove the shadow and make the website responsive in mobile.
My website's background colour is white: https://codemyquestion.blogspot.com/
This is how it is opened:
This is the expected output:
Below is the code:
<style>
.ddsmoothmenu-v ul {
margin: 0;
padding: 0;
width: 130px;
/* Main Menu Item widths */
list-style-type: none;
font: bold 12px Verdana;
border-bottom: 0px solid #ccc;
}
.ddsmoothmenu-v ul li {
position: relative;
}
.downarrowclass {
position: absolute;
top: 12px;
right: 7px;
}
.rightarrowclass {
position: absolute;
top: 10px;
right: 5px;
}
/* Top level menu links style */
.ddsmoothmenu-v ul li a {
display: block;
overflow: auto;
/*force hasLayout in IE7 */
height: 32px;
color: white;
text-decoration: none;
padding: 5px 5px 5px 25px;
border-bottom: 0px solid #778;
border-right: 0px solid #778;
}
.ddsmoothmenu-v ul li a:link, .ddsmoothmenu-v ul li a:visited, .ddsmoothmenu-v ul li a:active {
color: white;
background-image: url(http://3.bp.blogspot.com/-VCtcZunZJ2U/T9W7MM1uIXI/AAAAAAAAB9o/yVJ0Cad3Q0g/s1600/tab_bg.gif);
height: 22px;
background-repeat: repeat-x;
background-position: left center;
margin-bottom: 1px;
}
.ddsmoothmenu-v ul li a.selected {
/*CSS class that's dynamically added to the currently active menu items' LI A element*/
color: white;
background-image: url(http://2.bp.blogspot.com/-F0-PrDUYlX4/T9W7MrjME5I/AAAAAAAAB9w/0CLQurrHUjM/s1600/tabhover_bg.gif);
height: 22px;
background-repeat: repeat-x;
background-position: left center;
}
.ddsmoothmenu-v ul li a:hover {
color: white;
background-image: url(http://2.bp.blogspot.com/-F0-PrDUYlX4/T9W7MrjME5I/AAAAAAAAB9w/0CLQurrHUjM/s1600/tabhover_bg.gif);
height: 22px;
background-repeat: repeat-x;
background-position: left center;
}
/*Sub level menu items */
.ddsmoothmenu-v ul li ul {
position: absolute;
width: 170px;
/*Sub Menu Items width */
height: 22px;
top: 0;
font-weight: normal;
visibility: hidden;
}
/* Holly Hack for IE \*/
* html .ddsmoothmenu-v ul li {
float: left;
height: 1%;
}
* html .ddsmoothmenu-v ul li a {
height: 1%;
}
/*======= Vertical Drop Down Menu By Helper Blogger ========= */
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="http://helperblogger.ucoz.com/code/hb-smooth-menu.js"></script>
<script type="text/javascript">
})
</script>
<script type="text/javascript">
ddsmoothmenu.init({
mainmenuid: "smoothmenu2",
//Menu DIV id
orientation: 'v',
//Horizontal or vertical menu: Set to "h" or "v"
classname: 'ddsmoothmenu-v',
//class added to menu's outer DIV
//customtheme: ["#804000", "#482400"],
contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})
</script>
<div id="smoothmenu2" class="ddsmoothmenu-v">
<ul>
<li>
Home
</li>
<li>
Folder 0
<ul>
<li>
Sub Item 1.1
</li>
<li>
Sub Item 1.2
</li>
</ul>
</li>
<li>
Folder 1
<ul>
<li>
Sub Item 1.1
</li>
<li>
Sub Item 1.2
</li>
</ul>
</li>
<li>
Item 3
</li>
<li>
Folder 2
<ul>
<li>
Sub Item 2.1
</li>
</ul>
</li>
<li>
Create This
</li>
</ul>
<br style="clear: left" />
</div>
the black white nav menu:
HTML
<div class="sidenav">
<i class="fa fa-home"></i> About
<i class="fa fa-home"></i> Services
<i class="fa fa-home"></i> Clients
<i class="fa fa-home"></i> Contact
<div href="#" class="dropdown-btn">
<i class="fa fa-home"></i>
<i class="fa fa-caret-right"></i>Dropdown
<div class="dropdown-container">
Link 1
Link 2
Link 3
</div>
</div>
<i class="fa fa-home"></i> Search
</div>
CSS
.sidenav {
height: 100%;
width: 58px;
position: relative;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
padding: 20px 0;
white-space: nowrap;
overflow-x:hidden;
transition: all 0.2s ease-in-out;
}
.sidenav:hover {
width: 200px;
overflow-x:visible;
}
.sidenav .fa:not(.fa-caret-right){
margin-right:20px;
}
.sidenav a, .dropdown-btn {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 20px;
color: #818181;
display: block;
border: none;
background: none;
width: 100%;
text-align: left;
cursor: pointer;
outline: none;
}
.sidenav a:hover, .dropdown-btn:hover {
color: #f1f1f1;
position:relative;
}
.dropdown-btn:hover .dropdown-container{
display:block;
}
.dropdown-container {
display: none;
background-color: #262626;
padding-left: 8px;
position:absolute;
width:200px;
left:100%;
margin-top:-30px;
}
.fa-caret-right {
float: right;
padding-right: 8px;
display:none !important;
}
the sub-menu opens to the right side, if you want to open it from the left side use this code:
HTML
<div class="sidenav">
<i class="fa fa-home"></i> About
<i class="fa fa-home"></i> Services
<i class="fa fa-home"></i> Clients
<i class="fa fa-home"></i> Contact
<div href="#" class="dropdown-btn">
<i class="fa fa-home"></i>
Dropdown
<i class="fa fa-caret-left"></i>
<div class="dropdown-container">
Link 1
Link 2
Link 3
</div>
</div>
<i class="fa fa-home"></i> Search
</div>
CSS
.sidenav {
direction:rtl;
height: 100%;
width: 58px;
position: relative;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
padding: 20px 0;
white-space: nowrap;
overflow-x:hidden;
transition: all 0.2s ease-in-out;
}
.sidenav:hover {
width: 200px;
overflow-x:visible;
}
.sidenav .fa:not(.fa-caret-left){
margin-left:20px;
}
.sidenav a, .dropdown-btn {
padding: 6px 16px 6px 8px;
text-decoration: none;
font-size: 20px;
color: #818181;
display: block;
border: none;
background: none;
width: 100%;
text-align: right;
cursor: pointer;
outline: none;
}
.sidenav a:hover, .dropdown-btn:hover {
color: #f1f1f1;
position:relative;
}
.dropdown-btn:hover .dropdown-container{
display:block;
}
.dropdown-container {
display: none;
background-color: #262626;
padding-right: 8px;
position:absolute;
width:200px;
right:100%;
margin-top:-30px;
}
.fa-caret-right {
float: left;
display:none !important;
}
Funny, I recently made my online web-game mobile responsive too. I can help:
The problem is px. Don't use px for mobile websites. Instead, use percent (%) or viewport-width (vw) these will make it so the elements will resize to the browser size.
Absolute positioning. It will override the width of the page if the elements are not inside a div. If it's in a div, It'll not follow the width of that div. Instead, use position: relative because this is relative to the width or height of the viewport page.
Try resizing your browser on your laptop/desktop, and notice the elements match. Next:
Use the CSS3 max-width property so on laptop, it'll look fine. But on mobile devices it'll probably look like a smaller version of the desktop sized screen. For example:
will look the same on a mobile device but smaller.
Now, finally, you can use: <meta> HTML tag. It definitely works on texts, images, Etc. Here's how:
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
use these tricks and your website is ready for mobile devices.
Edit: I saw your website. Everything looks fine on my laptop.
What exactly is wrong?
you just need to make some changes in your style
<style>
.ddsmoothmenu-v ul {
margin: 0;
padding: 0;
width: 130px;
/* Main Menu Item widths */
list-style-type: none;
font: bold 12px Verdana;
border-bottom: 0px solid #ccc;
}
.ddsmoothmenu-v ul li {
position: relative;
}
.downarrowclass {
position: absolute;
top: 12px;
left: 7px;
transform:rotateY(180deg); /* change the right arrow to left arrow */
}
.rightarrowclass {
position: absolute;
top: 10px;
left: 5px;
transform:rotateY(180deg); /* change the right arrow to left arrow */
}
/* Top level menu links style */
.ddsmoothmenu-v ul li a {
display: block;
overflow: auto;
/*force hasLayout in IE7 */
height: 32px;
color: white;
text-decoration: none;
padding: 5px 5px 5px 25px;
border-bottom: 0px solid #778;
border-right: 0px solid #778;
}
.ddsmoothmenu-v ul li a:link, .ddsmoothmenu-v ul li a:visited, .ddsmoothmenu-v ul li a:active {
color: white;
background-image: url(http://3.bp.blogspot.com/-VCtcZunZJ2U/T9W7MM1uIXI/AAAAAAAAB9o/yVJ0Cad3Q0g/s1600/tab_bg.gif);
height: 22px;
background-repeat: repeat-x;
background-position: left center;
margin-bottom: 1px;
}
.ddsmoothmenu-v ul li a.selected {
/*CSS class that's dynamically added to the currently active menu items' LI A element*/
color: white;
background-image: url(http://2.bp.blogspot.com/-F0-PrDUYlX4/T9W7MrjME5I/AAAAAAAAB9w/0CLQurrHUjM/s1600/tabhover_bg.gif);
height: 22px;
background-repeat: repeat-x;
background-position: left center;
}
.ddsmoothmenu-v ul li a:hover {
color: white;
background-image: url(http://2.bp.blogspot.com/-F0-PrDUYlX4/T9W7MrjME5I/AAAAAAAAB9w/0CLQurrHUjM/s1600/tabhover_bg.gif);
height: 22px;
background-repeat: repeat-x;
background-position: left center;
}
/*Sub level menu items */
.ddsmoothmenu-v ul li ul {
position: absolute;
width: 170px;
/*Sub Menu Items width */
height: 22px;
top: 0;
font-weight: normal;
visibility: hidden;
left:-170px !important; /* move the sub-menu to the left */
box-shadow:none !important; /* remove the shadow */
}
/* Holly Hack for IE \*/
* html .ddsmoothmenu-v ul li {
float: left;
height: 1%;
}
* html .ddsmoothmenu-v ul li a {
height: 1%;
}
/*======= Vertical Drop Down Menu By Helper Blogger ========= */
</style>
I am working on a new version of a website. Right now I am almost satisfied with the results, except one problem. The website consists of a header (with logo and menu) and a content-part. I want it to work on both larg/small-size screens.
On a small screen I encounter one problem. When I expand the menu it is on top of the content-part, but the content-part is still clickable, so the menu-options are not clickable and the menu is not working right.
What I want is as follows (for small screen, i.e. Smartphone):
- When I click 'Show Menu' all menu-options will show up (Menu1, Menu2, Menu3, Menu4) and are clickable. Underlying text (div 'page') not visible (dissapears under the menu-options).
- When I click one of the menu-options, all options in submenu will show up and are clickable. Underlying text (div 'page') not visible.
I already searched and tried many options, but not with the expected result.
Thanks in advance for any hints :)
My html is as follows:
<body>
<div id="wrapper">
<div id="logo">
<img src="#" style="width:180px;height:50px;">
</div>
<div id="menu">
<label for="show-menu" class="show-menu">Show Menu</label>
<input type="checkbox" id="show-menu" role="button">
<ul id="menu">
<li>Home</li>
<li>Menu1 ↓
<ul class="hidden">
<li>Submenu11</li>
<li>Submenu12</li>
</ul>
</li>
<li>Menu2 ↓
<ul class="hidden">
<li>Menu21</li>
<li>Menu22</li>
<li>Menu23</li>
</ul>
</li>
<li>Menu3 ↓
<ul class="hidden">
<li>Menu31</li>
<li>Menu32</li>
<li>Menu33</li>
</ul>
</li>
<li>Menu4 ↓
<ul class="hidden">
<li>Menu41</li>
<li>Menu42</li>
<li>Menu43</li>
<li>Menu44</li>
<li>Menu45</li>
<li>Menu46</li>
</ul>
</li>
</ul>
</div>
<div id="header">
<h3>Header</h3><hr>
</div>
<div id="pageliquid">
<div id="page">Page-text<br />
</div>
</div>
</div>
</body>
My CSS is as follows:
body {
margin: 20px;
font-family: Tahoma, Arial;
font-size: 12pt;
color: #001245;
}
#wrapper {
width: 100%;
min-width: 1000px;
max-width: 2000px;
margin: 0 auto;
}
#logo {
height: 50px;
width: 100%;
position: static;
}
#menu {
height: 50px;
width: 100%;
position: static;
}
#header {
height: 75px;
width: 100%;
position: static;
}
#pageliquid {
width: 100%;
position: static;
}
#page {
top: 200px;
max-width: 100%;
position: absolute;
overflow: scroll;
bottom: 1px;
left: 20px;
right: 0px;
}
ul, img {
list-style-type:none;
margin:0;
padding:0;
position: absolute;
}
li {
display:inline-block;
float: left;
margin-right: 1px;
}
li a {
display:block;
min-width:200px;
height: 50px;
text-align: center;
line-height: 50px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: small;
color: #fff;
background: #0b0b3b;
text-decoration: none;
}
li:hover a {
background: #0b0b3b;
}
li:hover ul a {
background: #08088a;
color: #d8d8d8;
height: 40px;
line-height: 40px;
}
li:hover ul a:hover {
background: #08088a;
color: #ffffff;
}
li ul {
display: none;
}
li ul li {
display: block;
float: none;
}
li ul li a {
width: 160px;
min-width: 100px;
padding: 0 20px;
}
ul li a:hover + .hidden, .hidden:hover {
display: block;
}
.show-menu {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-decoration: none;
color: #fff;
background: #19c589;
text-align: center;
padding: 10px 0;
display: none;
}
input[type=checkbox] {
display: none;
-webkit-appearance: none;
}
input[type=checkbox]:checked ~ #menu{
display: block;
}
#media screen and (max-width : 760px) {
body {
margin: 0px;
}
#wrapper {
min-width: 0px;
margin: 0;
}
#header {
position: absolute;
}
#page {
left: 0px;
}
ul {
position: absolute;
width: 100%;
display: none;
}
li {
margin-bottom: 1px;
margin-right: 0px;
}
ul li, li a {
width: 100%;
}
li ul li a {
width: 100%;
padding: 0 0px;
}
.show-menu {
display:block;
}
}
The problem is with the z-index of the menu since it is underneath later elements on the page due to the fixed height and natural height of #menu and absolute positioning of that menu. You have duplicate ID's here, but forcing a higher z-index on #menu puts the navigation above other elements on the page. That also requires changing position: static; to position: relative; on #menu as well. Here's a demo - http://codepen.io/anon/pen/MJwoOL (PS - there were some overlapping issues with your nested li's and ul's that I tweaked a little in your media query, too, but are unrelated to your question here)
I have this html for my css menu:
<nav class="clearfix">
<ul class="clearix">
<li>Homepage</li>
<li>Services</li>
<li>Project Gallery</li>
<li>Contact Us</li>
</ul>
Menu
</nav>
nav {
height: 50px;
width: 100%;
background: #F00;
font-size: 14pt;
font-family: Arial;
position: relative;
border-bottom: 5px solid #FFFFFF;
}
nav ul {
padding: 0;
margin: 0 auto;
width: 100%;
height: 50px;
text-align: center;
}
nav li {
display: inline;
}
.clearfix:before,
.clearfix:after {
content: " ";
display: table;
}
.clearfix:after {
clear: both;
}
.clearfix {
*zoom: 1;
}
nav a {
color: #FFFFFF;
display: inline-block;
width: auto;
text-align: center;
text-decoration: none;
line-height: 50px;
}
nav li a {
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
padding-left: 10px;
padding-right: 10px;
}
nav li:last-child a {
border-right: 0;
}
nav a:hover, nav a:active {
background-color: #000000;
color:#FFFFFF;
}
nav a#pull {
display: none;
}
#media screen and (max-width: 600px) {
nav {
height: auto;
}
nav ul {
width: 100%;
display: block;
height: auto;
}
nav li {
width: 50%;
float: left;
position: relative;
}
nav li a {
border-bottom: 1px solid #FFFFFF;
border-right: 1px solid #FFFFFF;
}
nav a {
text-align: left;
width: 100%;
text-indent: 25px;
}
}
#media only screen and (max-width : 480px) {
nav {
border-bottom: 0;
}
nav ul {
display: none;
height: auto;
}
nav a#pull {
display: block;
color:#FFFFFF;
background-color: #F00;
width: 100%;
position: relative;
}
nav a#pull:after {
content:"";
background: url('nav-icon.png') no-repeat;
width: 30px;
height: 30px;
display: inline-block;
position: absolute;
rightright: 15px;
top: 10px;
}
}
#media only screen and (max-width : 320px) {
nav li {
display: block;
float: none;
width: 100%;
}
nav li a {
border-bottom: 1px solid #FFFFFF;
}
}
I am looking for a way to add sub menus and then second sub menus on on the first ones but still keep it as responsive as it is.
How can I do this?
http://jsfiddle.net/EYjnG/
JSFIDDLE DEMO
logic is just simple and have with this code
#submenu,#submenu2,#submenu3{
visibility:hidden; /*turn all the submenus visibility hidden */
}
#top_menu li.first:hover #submenu,#submenu li.second:hover #submenu2,#submenu2 li.second:hover #submenu3{
visibility:visible; /*On hover turn on visibility visible */
}
Complete code :
HTML:
<div id="top_menu"> <!--MAIN MENU -->
<ul>
<li class="first">menu1
<div id="submenu"> <!--First Submenu -->
<ul class="abc">
<li class="second">item1
<div id="submenu2"> <!--Second Submenu -->
<ul class="abc">
<li class="second">item1_1
<div id="submenu3"> <!--Third Submenu -->
<ul class="abc">
<li class="second">item1_1_1</li>
<li class="second">item1_1_2</li>
<li class="second">item1_1_3</li>
</ul>
</div> <!--third Submenu Ends here-->
</li>
<li class="second">item1_2</li>
<li class="second">item1_3</li>
</ul>
</div> <!--Second Submenu Ends here-->
</li>
<li class="second">item2
<div id="submenu2">
<ul class="abc">
<li class="second">item2_1</li>
<li class="second">item2_2</li>
<li class="second">item2_3</li>
</ul>
</div>
</li>
<li class="second">item3
<div id="submenu2">
<ul class="abc">
<li class="second">item3_1</li>
<li class="second">item3_2</li>
<li class="second">item3_3</li>
</ul>
</div>
</li>
</ul>
</div>
</li>
<li class="first">menu2
<div id="submenu">
<ul class="abc">
<li class="second">item1</li>
<li class="second">item2</li>
<li class="second">item3</li>
<li class="second">item4</li>
</ul>
</div>
</li>
</ul>
</div>
CSS:
ul{
padding:10px;
padding-right:0px;
}
li.first{
display:block;
display:inline-block;
padding:5px;
padding-right:25px;
padding-left:25px;
cursor:pointer;
}
li.second{
list-style:none;
margin:0px;
padding:5px;
padding-right:25px;
margin-bottom:5px;
cursor:pointer;
}
#submenu li.second:hover{
background:red;
border-radius:5px;
}
#submenu2 li.second:hover{
background:green;
border-radius:5px;
}
/*********MAIN LOGIC***************/
#submenu,#submenu2,#submenu3{
visibility:hidden;
}
#top_menu li.first:hover #submenu,#submenu li.second:hover #submenu2,#submenu2 li.second:hover #submenu3{
visibility:visible;
}
/**********STYLING SUBMENUS**************/
#submenu{
padding-right:0px;
text-align:left;
position:absolute;
background:white;
box-shadow:0px 0px 5px;
border-radius:5px;
}
#submenu2{
text-align:left;
position:absolute;
left:70px;
top:0px;
background:red;
box-shadow:0px 0px 5px;
border-radius:5px;
}
#submenu3{
text-align:left;
position:absolute;
left:80px;
top:0px;
background:green;
box-shadow:0px 0px 5px;
border-radius:5px;
}
just understand the logic behind this code and you can made as many submenus as you want.
There are many ways to go ahead about this.
I usually hide the sub menu uls with display: none and take them out of the content flow with position: absolute. Give the li containing the sub menu position: relative so that the sub menus are relative to their direct parents, then position the sub menus however you please using the top, right, bottom and left properties. Finally, change the sub menu to display: block through a :hover or whatever.
Here's a bare-bones example of this:
Markup:
<nav>
<ul>
<li><a>Link</a>
<ul>
<li><a>Sub link</a></li>
<li><a>Sub link</a></li>
<li><a>Sub link</a></li>
</ul>
</li>
</ul>
</nav>
CSS:
nav li {
position: relative;
}
nav li > ul {
position: absolute;
top: 100%;
display: none;
}
nav li:hover > ul {
display: block;
}
Here's a pen with this example. It looks like crap but you get the drill.
You can just keep nesting more sub-menus, but you'll probably want to use different positioning for second-and-lower-levels of sub menus.
However, please note that mobile browsers don't really support :hover. At least they don't treat it the same. You shouldn't make your sub menus accessible only on :hover. Consider adding some sort of class name toggle on click with javascript instead.
use hover in css like:
a:hover
or if your div id is "div1":
#div1:hover
I am not 100% sure if your asking how to make the id menu have a menu functionality or just a sub menu for your main nav.
If it is pertaining to a sub menu for your main nav then this will work just fine. If it's for the mobile menu then let me know and I'll work something out for you. (SOLVED)
This fiddle has the sub menu working while still being responsive the entire time. You can style it to your needs but it is a solid start.
nav ul li ul {
display: none;
position: absolute;
width: 100%;
top: 100%;
background: #000;
color: #fff;
}
nav ul li:hover ul {
display: block;
}
nav ul li ul li {
display: block;
-webkit-transition: .6s ease;
-moz-transition: .6s ease;
-ms-transition: .6s ease;
-o-transition: .6s ease;
}
nav ul li ul li:hover {
background: #c1c1c1;
color: #2b2b2b;
}
JSFIDDLE
JSFIDDLE with relative sized sub menu
Here is the mobile navigation working and the biggest problem was you had no jQuery library selected for the fiddle to run off of.
Mobile Nav
HTML
<div id="pull"><span>Menu</span>
</div>
CSS
div span {
color: #FFFFFF;
display: inline-block;
width: auto;
text-align: center;
text-decoration: none;
line-height: 50px;
padding-left: 10px;
padding-right: 10px;
}
I changed the id pull to a div because when it was an anchor tag all of the navs would lose their text color.
I have made a drop-down with a drop-down in it while still being responsive! Take a peak at this jsfiddle.
JSFIDDLE Drop-Down with a nested Drop-Down
Here's my take: http://codepen.io/teodragovic/pen/rmviJ
HTML
<nav>
<input type="checkbox" id="nav-toggle-1" />
<label for="nav-toggle-1" class="pull sub"><a>Menu</a></label>
<ul class="lvl-1">
<li>Homepage</li>
<li>
<input type="checkbox" id="nav-toggle-2" />
<label for="nav-toggle-2" class="sub"><a>Services</a></label>
<ul class="lvl-2">
<li>Service 1</li>
<li>Service 2</li>
<li>
<input type="checkbox" id="nav-toggle-3" />
<label for="nav-toggle-3" class="sub"><a>Service 3</a></label>
<ul class="lvl-3">
<li>Service 3 a</li>
<li>Service 3 b</li>
</ul>
</li>
<li>Service 4</li>
</ul>
</li>
<li>Project Gallery</li>
<li>Contact Us</li>
</ul>
</nav>
CSS
#import "compass";
/* globals */
* {box-sizing:border-box;}
ul {
margin: 0;
padding: 0;
}
input {
position: absolute;
top: -99999px;
left: -99999px;
opacity: 0;
}
nav {
height: 50px;
background: #F00;
font: 16px/1.5 Arial, sans-serif;
position: relative;
}
a {
color: #FFFFFF;
display: inline-block;
text-decoration: none;
line-height: 50px;
padding: 0 20px;
&:hover,
&:active {
background-color: #000000;
color:#FFFFFF;
}
}
/* nav for +600px screen */
ul.lvl-1 {
text-align: center;
#include pie-clearfix;
li {
display: inline;
}
}
ul.lvl-2,
ul.lvl-3 {
position: absolute;
width: 100%;
background: lighten(red, 15%);
display:none;
}
ul.lvl-3 {background: lighten(red, 30%);}
#nav-toggle-2:checked ~ ul.lvl-2,
#nav-toggle-3:checked ~ ul.lvl-3 {
display: block;
}
.pull {display: none;}
/* arrow thingy - crappy positioning, needs tinkering */
.sub {
position: relative;
cursor: pointer;
&:after {
position: absolute;
top: 40%;
right: 0;
content:"";
width: 0;
height: 0;
border-right: 6px solid transparent;
border-left: 6px solid transparent;
border-top: 6px solid white;
}
}
/* medium-ish nav */
#media screen and (max-width: 600px) {
nav {height: auto;}
a {
text-align: left;
width: 100%;
text-indent: 25px;
border-bottom: 1px solid #FFFFFF;
}
ul > li {
width: 50%;
float: left;
&:nth-of-type(odd) {
border-right: 1px solid white;
}
}
li:nth-of-type(even) ul.lvl-2,
li:nth-of-type(even) ul.lvl-3 {
position: relative;
width: 200%;
left: -100%;
}
li:nth-of-type(odd) ul.lvl-2,
li:nth-of-type(odd) ul.lvl-3 {
position: relative;
width: 200%;
left: 1px;
}
ul.lvl-2 li {background: lighten(red, 15%);}
ul.lvl-3 li {background: lighten(red, 30%);}
}
/* small-ish nav */
#media only screen and (max-width : 480px) {
.pull {
display: block;
width: 100%;
position: relative;
}
ul {
height: 0;
> li {
width: 100%;
&:nth-of-type(odd) {
border-right: none;
}
}
}
#nav-toggle-1:checked ~ ul.lvl-1 {
height: auto;
}
#nav-toggle-2:checked ~ ul.lvl-2,
#nav-toggle-3:checked ~ ul.lvl-3 {
//reverting stuff from previous breakpoint
left: 0;
width: 100%;
}
}
Markup is little modified from original since I find it easier to use classes than general selectors, especially when nesting lists.
It's CSS only (I'm using SASS+compass). :checked pseudo-class are used for toggling menus on and off. I removed link for services assuming that it will be used just for opening sub-menu (content-wise, you could always add something like "all services" in submenu if you want to keep that page in navigation).
Biggest challenge was styling middle breakpoint. Depending on position of parent list item (odd or even), child list is stretched to 200% (because parent is 50% wide) and positioned so it floats from left side. Small bug appears on level 3 regarding width of the list causing color bleed on edges.
Additionaly, display: block and display:none selectors could be replaced with max-height to add some cool css animation effects