CSS3 Menu Shows Up Wrong (CSS3/HTML5) - html

I've been working on a CSS3 menu, it's pretty much finished.. But, there is a little problem, the main li's are not really positioned good. If anyone could help me? I've got my site online and you could maybe inspect element? I think placing my code here would just take to much space etc..
Link: http://weveloped.com/
As you can see, the first li is placed horizontally, but the second one+ are placed vertically. How can I make sure all the li's are placed horizontally? It's probably something with the display's in the CSS code, but I can't seem to find the problem.
HTML CODE:
header {
width: 100%;
height: 85px;
background-color: rgba(24, 24, 24, 1);
position: fixed;
-webkit-transition: all 400ms ease;
-moz-transition: all 400ms ease;
-ms-transition: all 400ms ease;
-o-transition: all 400ms ease;
transition: all 400ms ease;
}
header ul,
header li {
padding: 0;
margin: 0;
}
header.sticky {
height: 50px;
/*background-color: rgba(24,24,24,0.6);*/
}
header nav {
text-align: right;
}
header nav li {
display: inline-block;
}
header nav li a {
display: inline-block;
height: 85px;
padding-left: 20px;
padding-right: 20px;
line-height: 85px;
color: #FFF;
text-decoration: none;
font-weight: 600;
}
header nav li:hover > a {
color: #A80000;
-webkit-transition: all 400ms ease;
-moz-transition: all 400ms ease;
-ms-transition: all 400ms ease;
-o-transition: all 400ms ease;
transition: all 400ms ease;
}
header nav li section.row {
overflow: hidden;
height: 0px;
-webkit-transition: all 200ms ease;
-moz-transition: all 200ms ease;
-ms-transition: all 200ms ease;
-o-transition: all 200ms ease;
transition: all 200ms ease;
}
header nav li section.row ul li {
display: block;
}
header nav li section.row ul li a {
display: block;
height: 25px;
line-height: 25px;
margin: 0px 17px 0px 17px;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 0;
padding-right: 0;
color: #555;
font-weight: 400;
border-bottom: 1px dashed #333941;
}
header nav li section.row ul li a:hover {
color: #A80000;
}
header nav li section.row ul li:last-child a {
border: none;
}
header nav li section.row ul li.title a {
color: #222;
font-weight: 600;
padding-top: 12px;
margin-left: 16px;
border: none;
}
header nav li:hover > section.row {
overflow: visible;
max-width: 960px;
height: 200px;
left: 0;
right: 0;
margin: 0 auto;
position: absolute;
background-color: #F5F5F5;
text-align: left;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
}
<header>
<nav>
<li>Homepage
</li>
<li>About Us
</li>
<li>Services
<section class="row">
<section class="three columns">
<ul>
<li class="title">Website Design
</li>
<li>Website Structure Design
</li>
<li>Mobile Website Design
</li>
<li>Parallax/Responsive Design
</li>
<li>Bespoke Design
</li>
</ul>
</section>
<section class="three columns">
<ul>
<li class="title">CManagement Systems
</li>
<li>WordPress
</li>
<li>Drupal
</li>
<li>Joomla
</li>
<li>Bespoke CMS
</li>
</ul>
</section>
<section class="three columns">
<ul>
<li class="title">Website Development
</li>
<li>CManagement System
</li>
<li>WebApp Development
</li>
<li>eCommerce Development
</li>
<li>Bespoke Development
</li>
</ul>
</section>
<section class="three columns">
<ul>
<li class="title">Our Work
</li>
<li>Portfolio
</li>
<li>Reviews
</li>
<li>Give a Review
</li>
</ul>
</section>
</section>
</li>
<li>Contact
</li>
</nav>
</header>
Thank you very much.

The problem is with the section element in the Services li: it wants to be as wide as the li's parent, so it pushes everything down. Give that section position: absolute; and you should be golden.

Related

How to create a menu with images and labels (HTML and CSS)?

I'm having a little problem, I was trying to make a menu combining items with image and other items with labels, as in the attached image, but it doesn''t work.
Next image shows how it is currently. With error.
I've tried with this code, but my "picture item" don't stand next to the "label item":
.sprite-icons {
background: url(../images/icons/sprite-icons_menu.png) no-repeat top left;
-webkit-transition: all 0.3s ease;
-o-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
width: 33px; height: 30px;
}
.sprite-icons.icon_home {
background-position: 0px 0px;
}
.icon_home:hover{
background-position: -48px 0px;
}
.sprite-icons.icon_home_active {
background-position: -48px 0px;
}
.sf-menu{
border-bottom: 1px solid black;
list-style-type:none;
line-height: 1.0;
text-align: center;
padding: 10px 10px 8px 10px;
float: left;
width: 99%;
}
.sf-menu a{
text-decoration: none;
color: #606060;
-webkit-transition: all 0.3s ease; -o-transition: all 0.3s ease; -moz-transition: all 0.3s ease;
}
.sf-menu a:hover{
color: #ffffff;
background-color: #ee1c24;
padding: 10px 6px 6px 6px;
}
.sf-menu li{
display: inline;
padding: 20px;
}
<nav>
<ul class="sf-menu">
<li><a href="" title="Home">
<div class="sprite-icons icon_home">
</div></a>
</li>
<li>A EMPRESA</li>
<li>SERVIÇOS</li>
<li>SISTEMA</li>
<li>TRABALHE CONOSCO</li>
<li>CONTATO</li>
</ul>
</nav>
How can I solve this?
Better solution should be use pseudo-element
:before
Example:
ul li
{
display: inline-block;
}
.icon-tutti:before {
content: "\e908";
}
span [class^=icon-] {
font-size: 1.3em;
margin-right: 10px;
color: #ff653e;
}
<ul>
<li><span class="icon-tutti"></span></li>
<li>Second Element</li>
<li>Third Element</li>
</ul>
You can also use an image url as content, but using icons should be better. Try fontAwesome for example.

How can i make a CSS drop down menu accessible for keyboard navigation?

I saw already some solutions, but i can't figure out how can i put some of these solutions in my code, or some solutions uses something that i can't use in my project.
Let's go to the question:
I need to make an already existing CSS drop-down menu accessible for keyboard navigation. I got some progress in opening the drop-down menu with [Tab] but i can't navigate into the options inside.
Here is my code:
.menu .options-menu-dropdown{
display: inline-block;
font-family: 'OpenSans Bold';
font-size: 16px;
color: #646464;
text-decoration: none;
cursor: pointer;
position: relative;
}
.menu .menu-dropdown{
z-index: -1;
visibility: hidden;
opacity: 0;
position: absolute;
top: 0;
right: 0;
min-width: 180px;
text-align: right;
overflow: hidden;
margin-top: -6px;
margin-right: -6px;
-webkit-transition: all 200ms ease-in-out;
-moz-transition: all 200ms ease-in-out;
-ms-transition: all 200ms ease-in-out;
-o-transition: all 200ms ease-in-out;
transition: all 200ms ease-in-out;
}
.menu .options-menu-dropdown:focus .menu-dropdown,
.menu .options-menu-dropdown:hover .menu-dropdown{
z-index: 100;
visibility: visible;
opacity: 1;
}
.menu .title-dropdown{
background-color: #005e8b;
font-size: 16px;
padding: 8px 6px;
white-space: nowrap;
border-bottom: 1px solid #b4b4b4;
color: #FFF;
}
.menu .menu-dropdown-item{
display: block;
background-color: white;
padding: 12px 32px 12px 12px;
text-decoration: none;
cursor: pointer;
font-size: 16px;
color: #323232;
-webkit-transition: all 200ms ease-in-out;
-moz-transition: all 200ms ease-in-out;
-ms-transition: all 200ms ease-in-out;
-o-transition: all 200ms ease-in-out;
transition: all 200ms ease-in-out;
border-top: #b4b4b4 1px solid;
border-left: #b4b4b4 1px solid;
border-right: #b4b4b4 1px solid;
}
.menu .menu-dropdown-item:last-child{
border-bottom: #b4b4b4 1px solid;
}
.menu .menu-dropdown-item:focus,
.menu .menu-dropdown-item:hover{
background-color: #b4b4b4;
color: #fff;
}
<div class="menu" align="center" >
<div class="options-menu-dropdown" tabindex="0">
<div>Test Menu</div>
<div class="menu-dropdown">
<div class="title-dropdown">Opened Test Menu</div>
Menu Item 1
Menu Item 2
Menu Item 3
</div>
</div>
</div>
code http://codepen.io/WillCodebit/pen/XpaqqJ
Note: I'm trying to avoid any javascript solution, because in this project I need to use GWT for any javascript, it is a pattern that I can't violate.
Thanks in advance.
EDIT
This menu should have a similar behavior than the account menu of Google. And the options inside must be accessible by keyboard too.
I had the exact same question – but did find my answer scattered over different places on the internet which is why I post my solution here. It is a solution that works without JavaScript. The secret lies in these pseudo classes:
li > a:hover + ul,
li > a:focus + ul,
li:focus-within > ul
Full HTML (Header section):
<header>
<nav>
<ul>
<li>
Page 1
<ul>
<li>
Sub page 1
</li>
<li>
Sub page 2
</li>
</ul>
</li>
<li>
Page 2
<ul>
<li>
Sub page 3
</li>
</ul>
</li>
</ul>
</nav>
</header>
Full CSS (without actual styling) – the first level elements are displayed next to each other (display: inline-block;), the second level elements are hidden and appear as soon as the parent element is active:
header ul {
list-style: none;
}
header nav > ul > li {
display: inline-block;
vertical-align: top;
}
header nav > ul > li > ul {
visibility: hidden;
opacity: 0;
}
header nav > ul > li > a:hover + ul,
header nav > ul > li > a:focus + ul,
header nav > ul > li:focus-within > ul {
visibility: visible;
opacity: 1;
}
From Heydon Pickering - Practical ARIA examples:
<nav role="navigation" aria-label="example with dropdowns">
<ul class="with-dropdowns">
<li>Home</li>
<li>
About
<ul aria-hidden="true" aria-label="submenu">
<li>Who we are</li>
<li>What we do</li>
<li>Why</li>
</ul>
</li>
<li>Blog</li>
<li>Contact</li>
</ul>
Thanks to Shannon Youg who tried to help.
I found a solution, but I had to put some Javascript to make it work.
HTML:
<div class="my-menu">
<a id="menuUser" href="javascript:showHideMenu()" class="">
<div>
Test
</div>
</a>
<ul id="menuUserDropdown" class="menu-dropdown">
<li>
<a href="#" class="menu-dropdown-item">
Option 1
</a>
</li>
<li>
<a href="#" class="menu-dropdown-item">
Option 2
</a>
</li>
<li>
<a href="#" class="menu-dropdown-item">
Option 3
</a>
</li>
</ul>
</div>
CSS:
.my-menu a{
display: inline-block;
font-family: 'OpenSans Bold';
font-size: 16px;
color: #646464;
text-decoration: none;
cursor: pointer;
position: relative;
}
.my-menu a div{
padding: 4px 5px 4px 0;
}
.my-menu a.opened div,
.my-menu a:hover div{
background-color: #c9252b;
color: #fff;
}
.my-menu .menu-dropdown.opened{
display: block;
}
.my-menu div{
display: inline-block;
vertical-align: middle;
}
.my-menu .menu-dropdown{
display: none;
margin: 0;
position: absolute;
z-index: 30;
background-color: #FFF;
list-style: none;
padding: 0;
border: 1px solid #b4b4b4;
}
.my-menu .menu-dropdown-item{
display: block;
background-color: white;
padding: 12px;
text-decoration: none;
width: 162px;
cursor: pointer;
font-size: 16px;
color: #323232;
}
.my-menu .menu-dropdown-item:focus,
.my-menu .menu-dropdown-item:hover{
background-color: #b4b4b4;
color: #fff;
}
Javascript, well, I made with GWT, but the logic is simple:
/* Just add or remove the class "opened" from "menuUser" and "menuUserDropdown".
You can put a "blur()" and "mouseLeave()" functions
to close the menu when the user moves away the cursor or
move the focus out of the menu too. */

How to change submenu appear to left side instead of right

I have a menu with submenu that open to the right instead of the left. You can see that here
Here is the html code:
<nav id="menu">
<ul class="parent-menu">
<li>
Home & Kitchen
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</li>
<li>
Electronics
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</li>
<li>
Clothing
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</li>
<li>
Cars & Motorbikes
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</li>
<li>
Books
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</li>
<li>
Support
<ul>
<li>Contact Us</li>
<li>Forum</li>
<li>Deliveries</li>
<li>T&C</li>
</ul>
</li>
</ul>
</nav>
and the css:
p,
ul,
li,
div,
nav {
padding: 0;
margin: 0;
}
#menu {
overflow: auto;
position: relative;
z-index: 2;
}
.parent-menu {
background-color: #0c8fff;
min-width: 200px;
float: left;
}
#menu ul {
list-style-type: none;
}
#menu ul li a {
padding: 10px 15px;
display: block;
color: #fff;
text-decoration: none;
}
#menu ul li a:hover {
background-color: #007ee9;
}
#menu ul li:hover > ul {
left: 200px;
-webkit-transition: left 200ms ease-in;
-moz-transition: left 200ms ease-in;
-ms-transition: left 200ms ease-in;
transition: left 200ms ease-in;
}
#menu ul li > ul {
position: absolute;
background-color: #333;
top: 0;
left: -200px;
min-width: 200px;
z-index: -1;
height: 100%;
-webkit-transition: left 200ms ease-in;
-moz-transition: left 200ms ease-in;
-ms-transition: left 200ms ease-in;
transition: left 200ms ease-in;
}
#menu ul li > ul li a:hover {
background-color: #2e2e2e;
}
I would like the submenu appear to the left
can you please assist me to solve this?
just change all the "left" css rules to be "right" and float the main menu to the right instead of the left.
p,
ul,
li,
div,
nav {
padding: 0;
margin: 0;
}
#menu {
overflow: auto;
position: relative;
z-index: 2;
}
.parent-menu {
background-color: #0c8fff;
min-width: 200px;
float: right;
}
#menu ul {
list-style-type: none;
}
#menu ul li a {
padding: 10px 15px;
display: block;
color: #fff;
text-decoration: none;
}
#menu ul li a:hover {
background-color: #007ee9;
}
#menu ul li:hover > ul {
left: 200px;
-webkit-transition: right 200ms ease-in;
-moz-transition: right 200ms ease-in;
-ms-transition: right 200ms ease-in;
transition: right 200ms ease-in;
}
#menu ul li > ul {
position: absolute;
background-color: #333;
top: 0;
right: -200px;
min-width: 200px;
z-index: -1;
height: 100%;
-webkit-transition: right 200ms ease-in;
-moz-transition: right 200ms ease-in;
-ms-transition: right 200ms ease-in;
transition: right 200ms ease-in;
}
#menu ul li > ul li a:hover {
background-color: #2e2e2e;
}
I just quickly went through the css and did that in your fiddle and it put the main menu on the right and the submenu to the left of the main menu.

Auto width for submenu

I can't get this to work, but in my dropdown menu I just simply can't find a way to make the dropdown menu (for example on account) have it scale with the text.
I tried many things, but only so far a static width is working but that is not what I want
<div class="menu-wrap">
<div class="menu">
<ul class="menu-inner">
<li class="home">Home</li>
<li class="account">Mijn Account
<ul>
<li>Mijn website</li>
<li>Profiel</li>
<li>Persoonlijke gegevens</li>
<li>Voorkeuren</li>
<li>Email instellingen</li>
<li>Log uit</li>
</ul>
</li>
<li class="pages">Mijn pagina's
<ul>
<li>Mijn pagina's</li>
<li>Maak een nieuwe pagina</li>
<li>Verander pagina volgorde</li>
</ul>
</li>
<li class="messages">Mijn berichten
<ul>
<li>Alle privè berichten</li>
<li>Verzonden berichten</li>
<li>Verwijderde berichten</li>
<li>Ongelezen berichten</li>
</ul>
</li>
<li class="forum">Forum
<ul>
<li>Nieuwste berichten</li>
<li>Overzicht</li>
<li>Mijn berichten</li>
<li>Top posters</li>
<li>Zoek topic</li>
</ul>
</li>
<li class="search">Zoeken
<ul>
<li>Zoeken</li>
<li>Vandaag jarig</li>
<li>Online leden</li>
<li>Alle leden</li>
<li>Zoek topic</li>
</ul>
</li>
<li class="online">Online (x)
</ul>
</div>
</div>
and the css code:
.menu-wrap{
position: relative;
background-color: rgba(0,0,0,0.8);
height: 30px;
width: 100%;
text-align: center;
}
.menu {
position: relative;
width: 860px;
margin: 0px auto;
height: 30px;
line-height: 30px;
}
.menu ul {
text-align: left;
display: inline;
margin: 0;
padding: 0;
list-style: none;
}
.menu ul li {
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 5px 22px;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
}
.menu ul li:hover {
background-color: rgba(0,0,0,0.4);
}
.menu ul li a {
color: #fff;
text-decoration: none;
font-size: 14px;
}
.menu ul li ul {
padding: 0;
position: absolute;
top: 28px;
left: 0;
width: auto;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
background-color: rgba(0,0,0,0.4)
}
.menu ul li ul li {
color: #fff;
}
.menu ul li ul li:hover { background-color: rgba(0,0,0,0.4);}
.menu ul li:hover ul {
display:inline-block;
opacity: 1;
visibility: visible;
}
All I want is have the sub menus auto scale in width with the text!
You are going to have to add a white-space property to the .menu ul li ul li rule like so:
.menu ul li ul li {
white-space: nowrap;
}

Adding a margin messing up display of drop-down menu

The issue I'm having is that when I add a margin to my hover over drop down navmenu it messes up all the content which was meant to drop down and clusters it all up nearly just above it. Although before adding a margin the navigation menu worked perfectly fine, and yes removing the margin fixes the issue but I need to add a margin.
Here is my CSS, let me know if you need the HTML also. (Note, I am doing this on Notepad++ as HTML >4<)
#navmenu a {
text-decleration: none;
display: block;
width: 124px;
height: 27px;
line-height: 25px;
background-color: ;
border: 1px solid #CCC;
border-radius: 5px;
font-family: Magneto;
font-size: 20px;
color: ffffff;
transition: ease-in all 400ms;
-moz-transition: ease-in all 300ms;
-webkit-transition: ease-in all 300ms;
-o-transition: ease-in all 300ms;
margin: -40px;
}
#navmenucontainer {
margin: 15px;
margin-left: 10px;
width: 230px;
height: auto;
float: left;
}
Here is the Relevent HTML:
<div id="navmenucontainer">
<ul id="navmenu">
<li>
Menu
<ul>
<li>Education
</li>
<li>Hobbies
</li>
<li>Interests
</li>
</ul>
</li>
</ul>
</div>
demo - http://jsfiddle.net/victor_007/fajLeLsy/
it looks like you want to do something like this
don't give -margin for a
#navmenu a {
text-decleration: none;
display: block;
width: 124px;
height: 27px;
line-height: 25px;
background-color: ;
border: 1px solid #CCC;
border-radius: 5px;
font-family: Magneto;
font-size: 20px;
color: ffffff;
}
#navmenucontainer {
margin: 15px;
width: 230px;
height: auto;
}
ul {
margin: 0;
padding: 0;
list-style: none;
}
ul li:hover ul {
opacity: 1;
visibility: visible;
}
ul li ul {
opacity: 0;
visibility: hidden;
transition: ease-in all 400ms;
-moz-transition: ease-in all 300ms;
-webkit-transition: ease-in all 300ms;
-o-transition: ease-in all 300ms;
}
<div id="navmenucontainer">
<ul id="navmenu">
<li> Menu
<ul>
<li>Education
</li>
<li>Hobbies
</li>
<li>Interests
</li>
</ul>
</li>
</ul>
</div>