CSS/HTML Menu going crazy - html

Hello Mates,
I'm trying to build a CSS menu that is displayed above. So far I wrote this HTML:
<div class="left-menu">
<ul class="menu-left">
<li id="current" class="parent active item5">
<span>ღვინო</span>
<ul>
<li class="parent item6">
<span>TELIANI VALLEY</span>
<ul>
<li class="item7">
<span>ლეგენდა</span>
</li>
<li class="item8">
<span>ღვინოები</span>
</li>
<li class="item9">
<span>ჯილდოები</span>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
and this is my CSS:
/* 1 */
.left-menu ul {
width: 145px;
margin: 0;
padding: 0;
list-style: none;
}
.left-menu ul li {
list-style: none;
margin: 0;
padding: 0;
}
.left-menu ul li {
width: 145px;
margin: 0;
padding: 0;
height: 20px;
background:#fff;
}
.left-menu ul li a {
width:131px;
height:20px;
padding-left: 14px;
float: left;
font: normal 12px calibri, sylfaen, georgia, arial, verdana;
color: #7b2029; text-decoration: none;
}
.left-menu ul li:hover, .left-menu ul li#current {
width: 145px;
height: 20px;
color:#fff;
text-decoration: none;
}
.left-menu ul li#current a {
width: 131px;
height: 20px;
padding-left: 14px;
color: #fff;
text-decoration: none;
background: #7b2029;
display:block;
}
/* 2 */
.left-menu ul li ul {
width:145px;
padding:0;
margin: 2px 0 0 0;
float: left;
list-style: none;
}
.left-menu ul li ul li {
width: 137px;
margin: 0;
padding: 0;
height: 20px;
list-style: none;
padding-left: 8px;
}
.left-menu ul li ul li a {
width: 120px;
height: 20px;
padding-top: 0px;
font: normal 12px/20px calibri, sylfaen, georgia, arial, verdana;
background:#887b33;
}
/* 3 */
and I'm getting displayed this crap:
Can someone tell me why? I haven't experience such thing before...

Link to example fiddle I have created:
Fiddle...
I didn't bother with hover effects, and colors/font styles. You can always change it...
Tested on mozilla and IE (ain't got chrome at work).
I hope it helps.
Daniel

Related

How do I make the width of my sub-menu links the same as its parent?

I am very new to programming and am working on a website as a project for a class. I am attempting to create a drop down menu, but I continually run into an issue where my links in the drop down sub-menu are not taking up the full width I would like. See the pic below.
https://i.stack.imgur.com/u6koe.png
I would like the link and thus the hovered white background to extend the full width of the sub-menu but I cannot figure out how to make it work.
Here is my HTML:
<header id="mainheader">
<nav>
<ul id="menu">
<li>About Me</li>
<li>Creativity
<ul class="submenu">
<li>Skiing</li>
<li>Island</li>
<li>Cooking</li>
</ul>
</li>
<li>Revisions</li>
</ul>
</nav>
</header>
Here is my CSS:
body {
margin-top: 0px;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin-left: auto;
margin-right: auto;
background-color: aquamarine;
}
#mainheader {
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
background-color: #818181;
text-align: center;
}
#menu {
padding: 0;
margin: 0;
}
#menu li {
display: inline-block;
list-style: none;
padding-top: 10px;
padding-bottom: 10px;
position: relative;
}
#menu li a {
text-decoration: none;
font-weight: bold;
color: white;
padding: 10px 30px;
}
#menu li a:hover {
background-color: white;
color: black;
}
#menu li ul.submenu {
height: auto;
width: 133px;
background: #818181;
position: absolute;
display: none;
padding: 0;
margin-top: 10px;
}
#menu li:hover ul.submenu {
display: block;
}
#menu li ul.submenu li {
width: 133px;
}
#menu li ul.submenu li a {
text-decoration: none;
padding: 10px 0px;
}
Any assistance is appreciated.
Add display: inline-block; and width: 100%; to your #menu li ul.submenu li a css rule.
body {
margin-top: 0px;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin-left: auto;
margin-right: auto;
background-color: aquamarine;
}
#mainheader {
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
background-color: #818181;
text-align: center;
}
#menu {
padding: 0;
margin: 0;
}
#menu li {
display: inline-block;
list-style: none;
padding-top: 10px;
padding-bottom: 10px;
position: relative;
}
#menu li a {
text-decoration: none;
font-weight: bold;
color: white;
padding: 10px 30px;
}
#menu li a:hover {
background-color: white;
color: black;
}
#menu li ul.submenu {
height: auto;
width: 133px;
background: #818181;
position: absolute;
display: none;
padding: 0;
margin-top: 10px;
}
#menu li:hover ul.submenu {
display: block;
}
#menu li ul.submenu li {
width: 133px;
}
#menu li ul.submenu li a {
text-decoration: none;
padding: 10px 0px;
display: inline-block;
width: 100%;
}
<header id="mainheader">
<nav>
<ul id="menu">
<li>About Me</li>
<li>Creativity
<ul class="submenu">
<li>Skiing</li>
<li>Island</li>
<li>Cooking</li>
</ul>
</li>
<li>Revisions</li>
</ul>
</nav>
</header>

How to center my Nav Bar?

I have had many attempts but I have failed on all attempts, This is my code I've created but I cannot find a way to center my navigation bar. Here is my code
<div id="nav">
<nav id="primary_nav_wrap">
<ul>
<li class="current-menu-item">Home</li>
<li>About</li>
<li>Models
<ul>
<li>Lite</li>
<li>Domestic</li>
<li>Regional</li>
<li>Continental</li>
<li></li>
</ul>
</li>
<li>Benefits</li>
<li>Extras</li>
<li>Technical</li>
<li>Other Products
<ul>
<li>EMA Loader</li>
<li>Portable Airstairs</li>
</ul>
</li>
<li>Testimonials</li>
<li>FAQ's</li>
</ul>
</nav>
</div>
<style type="text/css">
#primary_nav_wrap {
margin-top: 15px;
}
#primary_nav_wrap ul {
list-style: none;
position: relative;
padding: 0
}
#primary_nav_wrap ul a {
display: block;
color: #333;
text-decoration: none;
font-weight: 700;
font-size: 13px;
line-height: 32px;
padding: 0 15px;
font-family: "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif
}
#primary_nav_wrap ul li {
position: relative;
float: left;
margin-right: auto;
margin-left: auto;
padding: 0
}
#primary_nav_wrap ul li.current-menu-item {
background: #ddd
}
#primary_nav_wrap ul li:hover {
background: #75D1FF;
}
#primary_nav_wrap ul ul {
display: none;
position: absolute;
top: 100%;
left: 0;
background: #fff;
padding: 0
}
#primary_nav_wrap ul ul li {
float: none;
width: 200px
}
#primary_nav_wrap ul ul a {
line-height: 120%;
padding: 10px 15px
}
</style>
Please try and help me as the website I'm making requires the nav bar to be in the center
Please find the updated code, it works well for me, hope it will resolve your issue.
<div id="nav">
<nav id="primary_nav_wrap">
<ul>
<li class="current-menu-item">Home</li>
<li>About</li>
<li>Models
<ul>
<li>Lite</li>
<li>Domestic</li>
<li>Regional</li>
<li>Continental</li>
<li></li>
</ul>
</li>
<li>Benefits</li>
<li>Extras</li>
<li>Technical</li>
<li>Other Products
<ul>
<li>EMA Loader</li>
<li>Portable Airstairs</li>
</ul>
</li>
<li>Testimonials</li>
<li>FAQ's</li>
</ul>
</nav>
</div>
<style type="text/css">
#primary_nav_wrap {
margin-top: 15px;
text-align:center;
}
#primary_nav_wrap ul {
list-style: none;
position: relative;
padding: 0;
margin:0px auto;
display:inline-block;
}
#primary_nav_wrap ul a {
display: block;
color: #333;
text-decoration: none;
font-weight: 700;
font-size: 13px;
line-height: 32px;
padding: 0 15px;
font-family: "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif
}
#primary_nav_wrap ul li {
position: relative;
float: left;
margin-right: auto;
margin-left: auto;
padding: 0
}
#primary_nav_wrap ul li.current-menu-item {
background: #ddd
}
#primary_nav_wrap ul li:hover {
background: #75D1FF;
}
#primary_nav_wrap ul ul {
display: none;
position: absolute;
top: 100%;
left: 0;
background: #fff;
padding: 0
}
#primary_nav_wrap ul ul li {
float: none;
width: 200px
}
#primary_nav_wrap ul ul a {
line-height: 120%;
padding: 10px 15px
}
</style>
Here are two lines to add to your css:
#primary_nav_wrap {
margin-top: 15px;
width: 800px;
margin: 0 auto;
}
adding the width and margin: 0 auto will help you. Only adding the margin: 0 auto will not work it needs the width to work.
Simple solution:
#nav{
width:100%;
text-align:center;
}
#primary_nav_wrap {
margin: 15px auto 0 auto;
width:780px;
}
http://jsfiddle.net/e8rqxbe5/1/
Other solution is:
#primary_nav_wrap {
display: table;
margin: 0 auto;
margin: 15px auto 0 auto;
}
#primary_nav_wrap ul {
display: table-cell;
list-style: none;
position: relative;
padding: 0;
}
http://jsfiddle.net/u5xko1dn/1/
#nav{
width:100%;
text-align:center;
}
#primary_nav_wrap {
margin-top: 15px;
}
#primary_nav_wrap ul {
list-style: none;
position: relative;
padding: 0
}
#primary_nav_wrap ul a {
display: block;
color: #333;
text-decoration: none;
font-weight: 700;
font-size: 13px;
line-height: 32px;
padding: 0 15px;
font-family: "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif
}
#primary_nav_wrap ul li {
position: relative;
float: left;
margin-right: auto;
margin-left: auto;
padding: 0
}
#primary_nav_wrap ul li.current-menu-item {
background: #ddd
}
#primary_nav_wrap ul li:hover {
background: #75D1FF;
}
#primary_nav_wrap ul ul {
display: none;
position: absolute;
top: 100%;
left: 0;
background: #fff;
padding: 0
}
#primary_nav_wrap ul ul li {
float: none;
width: 200px
}
#primary_nav_wrap ul ul a {
line-height: 120%;
padding: 10px 15px
}
/* center */
#primary_nav_wrap {
display: -webkit-flex;
display: flex;
-webkit-justify-content: center;
justify-content: center;
-webkit-align-items: center;
align-items: center;
//width: 100%;
//height: auto;
//background-color: lightgrey;
}
ul {
//background-color: cornflowerblue;
//padding: 1rem;
//margin: 1rem;
-webkit-align-self: center;
align-self: center;
}
/* || center */
<div id="nav">
<nav id="primary_nav_wrap">
<ul>
<li class="current-menu-item">Home</li>
<li>About</li>
<li>Models
<ul>
<li>Lite</li>
<li>Domestic</li>
<li>Regional</li>
<li>Continental</li>
<li></li>
</ul>
</li>
<li>Benefits</li>
<li>Extras</li>
<li>Technical</li>
<li>Other Products
<ul>
<li>EMA Loader</li>
<li>Portable Airstairs</li>
</ul>
</li>
<li>Testimonials</li>
<li>FAQ's</li>
</ul>
</nav>
</div>

Can't use certain Width - CSS menu

I got this menu and I need all items to be the same width (155px).
But I don't seem to be doing it the right way, I would appreciate some tips and possible solutions.
#menu {
width: 1000px;
height: 625px;
text-transform: uppercase;
text-align: left;
font-size: 10px;
margin: 0 auto;
font-family: 'Raleway', sans-serif;
font-weight: 400;
}
#menu span {
padding-left: 11px;
}
#menu ul {
margin: 0;
padding: 25px 0 0 0;
}
#menu li {
background: url(../img/menu_dots.jpg) no-repeat;
display: inline;
padding-bottom: 614px;
padding-top: 25px;
width: 155px;
}
#menu li a {
text-decoration: none;
color: #D1D3D4;
}
#menu li a:hover {
color: #000;
font-weight: 700;
}
#menu li .current {
color: #000;
font-weight: 700;
}
<div id="menu">
<ul>
<li><span>OCTO</span>
</li>
<li><span>EQUIPA</span>
</li>
<li><span>RECONHECIMENTO</span>
</li>
<li><span>PARCEIROS</span>
</li>
<li><span>PORQUE NÃO?</span>
</li>
<li><span>CONTACTOS</span>
</li>
</ul>
</div>
Easiest solution would be to change the display on the list items (#menu li) from inline to inline-block.
#menu {
width: 1000px;
height: 625px;
text-transform: uppercase;
text-align: left;
font-size: 10px;
margin: 0 auto;
font-family: 'Raleway', sans-serif;
font-weight: 400;
}
#menu span {
padding-left: 11px;
}
#menu ul {
margin: 0;
padding: 25px 0 0 0;
}
#menu li {
background: url(../img/menu_dots.jpg) no-repeat;
display: inline-block;
padding-bottom: 614px;
padding-top: 25px;
width: 155px;
}
#menu li a {
text-decoration: none;
color: #D1D3D4;
}
#menu li a:hover {
color: #000;
font-weight: 700;
}
#menu li .current {
color: #000;
font-weight: 700;
}
<div id="menu">
<ul>
<li><span>OCTO</span>
</li>
<li><span>EQUIPA</span>
</li>
<li><span>RECONHECIMENTO</span>
</li>
<li><span>PARCEIROS</span>
</li>
<li><span>PORQUE NÃO?</span>
</li>
<li><span>CONTACTOS</span>
</li>
</ul>
</div>
Yes, it is a good solution but after adding display:inline-block; to li actual width wil be 166px, because of padding-left:11px also mind it;
you need to add into the menu li the properties overflow:hidden and max-width:155px and min-width:155px

How to create an unordered list inside an unordered list in a list menu?

On my page, I'm trying to create an unordered list within an unordered list in my menu so that there is a second dropdown menu. The problem is that the second dropdown menu displays at the same time as the first.
.menu {
border: none;
border: 0px;
margin: 0px;
padding: 0px;
font: 67.5%"Lucida Sans Unicode", "Bitstream Vera Sans", "Trebuchet Unicode MS", "Lucida Grande", Verdana, Helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
}
.menu ul {
background: #333333;
height: 35px;
list-style: none;
margin: 0;
padding: 0;
}
.menu li {
float: left;
padding: 0px;
}
.menu li a {
background: #333333 url("http://4.bp.blogspot.com/_jM8-wHc3NKY/TQsZSeQYKQI/AAAAAAAAAGU/0AgHYW2zktQ/s1600/seperator.gif") bottom right no-repeat;
color: #cccccc;
display: block;
font-weight: normal;
line-height: 35px;
margin: 0px;
padding: 0px 25px;
text-align: center;
text-decoration: none;
}
.menu li a:hover,
.menu ul li:hover a {
background: #2580a2 url("http://3.bp.blogspot.com/_jM8-wHc3NKY/TQsZNT36uyI/AAAAAAAAAGM/F8t08m7-5tw/s1600/hover.gif") bottom center no-repeat;
color: #FFFFFF;
text-decoration: none;
}
.menu li ul {
background: #333333;
display: none;
height: auto;
padding: 0px;
margin: 0px;
border: 0px;
position: absolute;
width: 225px;
z-index: 200;
/*top:1em;
/*left:0;*/
}
.menu li:hover ul {
display: block;
}
.menu li li {
background: url('http://1.bp.blogspot.com/_jM8-wHc3NKY/TQsZUcZYwkI/AAAAAAAAAGY/zNSlkfCsai8/s1600/sub_sep.gif') bottom left no-repeat;
display: block;
float: none;
margin: 0px;
padding: 0px;
width: 225px;
}
.menu li:hover li a {
background: none;
}
.menu li ul a {
display: block;
height: 35px;
font-size: 12px;
font-style: normal;
margin: 0px;
padding: 0px 10px 0px 15px;
text-align: left;
}
.menu li ul a:hover,
.menu li ul li:hover a {
background: #2580a2 url('http://4.bp.blogspot.com/_jM8-wHc3NKY/TQsZPiSwCMI/AAAAAAAAAGQ/VBSL8auDxzc/s1600/hover_sub.gif') center left no-repeat;
border: 0px;
color: #ffffff;
text-decoration: none;
}
.menu p {
clear: left;
}
<div class="menu">
<ul>
<li>Games
<ul id="1">
<li>minecraft
<ul id="2">
<li>Projects
</li>
<li>Texture Packs
</li>
<li>Skins
</li>
<li>Mods
</li>
<li>Other Stuff
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
The key to getting the sub-menu working is to use the child combinator (>) to target direct descendants.
A child combinator describes a childhood relationship between two elements. A child combinator is made of the "greater-than sign" (U+003E, >) character and separates two sequences of simple selectors.
(http://www.w3.org/TR/css3-selectors/#child-combinators)
The following changes are required:
Add the .menu li ul ul setting left: 100%; and top: 0;. This will tell all sub-menus to be positioned against the right edge of its parent menu.
Change .menu li:hover ul to .menu li:hover > ul. This will ensure that only the direct child ul is shown when the user hovers over the parent li.
Change .menu li ul a:hover, .menu li ul li:hover a to .menu li ul li:hover > a. This will ensure that only the direct child as are highlighted when the user hovers over the parent li.
.menu {
border: none;
border: 0px;
margin: 0px;
padding: 0px;
font: 67.5%"Lucida Sans Unicode", "Bitstream Vera Sans", "Trebuchet Unicode MS", "Lucida Grande", Verdana, Helvetica, sans-serif;
font-size: 14px;
font-weight: bold;
}
.menu ul {
background: #333333;
height: 35px;
list-style: none;
margin: 0;
padding: 0;
}
.menu li {
float: left;
padding: 0px;
}
.menu li a {
background: #333333 url("http://4.bp.blogspot.com/_jM8-wHc3NKY/TQsZSeQYKQI/AAAAAAAAAGU/0AgHYW2zktQ/s1600/seperator.gif") bottom right no-repeat;
color: #cccccc;
display: block;
font-weight: normal;
line-height: 35px;
margin: 0px;
padding: 0px 25px;
text-align: center;
text-decoration: none;
}
.menu li a:hover,
.menu ul li:hover a {
background: #2580a2 url("http://3.bp.blogspot.com/_jM8-wHc3NKY/TQsZNT36uyI/AAAAAAAAAGM/F8t08m7-5tw/s1600/hover.gif") bottom center no-repeat;
color: #FFFFFF;
text-decoration: none;
}
.menu li ul {
background: #333333;
display: none;
height: auto;
padding: 0px;
margin: 0px;
border: 0px;
position: absolute;
width: 225px;
z-index: 200;
}
.menu li ul ul {
top: 0;
left: 100%;
}
.menu li:hover > ul {
display: block;
}
.menu li li {
background: url('http://1.bp.blogspot.com/_jM8-wHc3NKY/TQsZUcZYwkI/AAAAAAAAAGY/zNSlkfCsai8/s1600/sub_sep.gif') bottom left no-repeat;
display: block;
float: none;
margin: 0px;
padding: 0px;
width: 225px;
}
.menu li:hover li a {
background: none;
}
.menu li ul a {
display: block;
height: 35px;
font-size: 12px;
font-style: normal;
margin: 0px;
padding: 0px 10px 0px 15px;
text-align: left;
}
.menu li ul li:hover > a {
background: #2580a2 url('http://4.bp.blogspot.com/_jM8-wHc3NKY/TQsZPiSwCMI/AAAAAAAAAGQ/VBSL8auDxzc/s1600/hover_sub.gif') center left no-repeat;
border: 0px;
color: #ffffff;
text-decoration: none;
}
<div class="menu">
<ul>
<li>Games
<ul id="1">
<li>minecraft
<ul id="2">
<li>Projects
</li>
<li>Texture Packs
</li>
<li>Skins
</li>
<li>Mods
</li>
<li>Other Stuff
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>

CSS Bug with inline ul li in IE7

I've got a little issue with a inline menu, bug only appears in ie7. The only menu li that has another menu underneath it, is not inline with the rest, the rest seem to appear pushed down.
HTML
<div id="topnav">
<ul id="jsddm">
<li id="">
<a id="" href="/">Home</a>
</li>
<li id="">
About
<ul style="visibility: hidden;">
<li>
Board
</li>
<li>
Contact
</li>
</ul>
</li>
<li>
Practices
</li>
<li>
How we work
</li>
<li>
Patients
</li>
<li>
News & Links
</li>
<li>
Link
</li>
</ul>
</div>
CSS
#jsddm
{ margin: 0;
padding: 0;
width: 100%;
}
#jsddm li
{
display: inline-block;
list-style: none;
font: 12px Tahoma, Arial;
width: 100px;
text-align: center;
}
*+html #jsddm li { display:inline }
* html #jsddm li { display:inline }
#jsddm ul li
{
display: block;
font: 12px Tahoma, Arial;
}
#jsddm li ul
{
margin: 0 0 0 0;
padding: 0;
position: absolute;
visibility: hidden;
border-top: 0px solid white;
*margin: 0 0 0 -50px; /* IE 7 and below */
/* margin: 0 0 0 -50px\9; IE 8 and below */
}
#jsddm ul li ul li
{
font: 12px Tahoma, Arial
}
#jsddm li a
{
display: block;
background: #009EE0;
padding: 0;
line-height: 28px;
text-decoration: none;
border-right: 0px solid white;
width: 70px;
color: #EAFFED;
white-space: nowrap;
font-weight: bold;
width: 100%;
}
#jsddm li a:hover
{ background: #1A4473}
#jsddm li ul li
{
float: none;
*margin: -2px 0 0 0;
*padding:0;
}
+html #jsddm li ul li { }
#jsddm li ul li a
{
width: auto;
background: #009EE0
font-weight: bold;
}
#jsddm li ul li a:hover
{ background: #0E559C }
It uses a jquery function to display the dropdownmenu but it does'nt effect the static html/css.
Thanks.
IE7 doesn't support inline-block. Try to float the elements in it - http://jsfiddle.net/SsDnd/1/
#jsddm li
{
display: inline-block;
list-style: none;
font: 12px Tahoma, Arial;
width: 100px;
text-align: center;
*float: left;
}