How can create menu for unlimited items? - php

I've a css menu, but this getting problem when I add more menu items.
What should I do to create a menu for unlimited menu items ?
my css
<style type="text/css">
#nav, #nav ul{
margin:0;
padding:0;
list-style-type:none;
list-style-position:outside;
position:relative;
line-height:1.5em;
}
#nav a:link, #nav a:active, #nav a:visited{
display:block;
padding:0px 5px;
border:1px solid #333;
color:#fff;
text-decoration:none;
background-color:#333;
}
#nav a:hover{
background-color:#fff;
color:#333;
}
#nav li{
float:left;
position:relative;
}
#nav ul {
position:absolute;
width:12em;
top:1.5em;
display:none;
}
#nav li ul a{
width:12em;
float:left;
}
#nav ul ul{
top:auto;
}
#nav li ul ul {
left:12em;
margin:0px 0 0 10px;
}
#nav li:hover ul ul, #nav li:hover ul ul ul, #nav li:hover ul ul ul ul{
display:none;
}
#nav li:hover ul, #nav li li:hover ul, #nav li li li:hover ul, #nav li li li li:hover ul{
display:block;
}
</style>
my sample menu for static items
<ul id="nav">
<li>1 HTML</li>
<li>2 CSS
<ul>
<li>3.1 jQuery
<ul>
<li>3.1.1 Download
<ul>
<li>3.1 jQuery
<ul>
<li>3.1.1 Download
<!-- If I add this ul here then it doesn't follow the current css.
<ul>
<li>3.1 jQuery
<ul>
<li>3.1.1 Download</li>
<li>3.1.2 Tutorial</li>
</ul>
</li>
<li>3.2 Mootools</li>
<li>3.3 Prototype</li>
</ul>
-->
</li>
<li>3.1.2 Tutorial</li>
</ul>
</li>
<li>3.2 Mootools</li>
<li>3.3 Prototype</li>
</ul>
</li>
<li>3.1.2 Tutorial</li>
</ul>
</li>
<li>3.2 Mootools</li>
<li>3.3 Prototype</li>
</ul>
</li>
<li>3 Javascript
<ul>
<li>3.1 jQuery
<ul>
<li>3.1.1 Download</li>
<li>3.1.2 Tutorial</li>
</ul>
</li>
<li>3.2 Mootools</li>
<li>3.3 Prototype</li>
</ul>
</li>
</ul>
(suppose,I want to show product menu where product categories will come from database. so its also required to use some php,mysql.just show me how should I design the css menu for the unknown number of category and subcategory)
-Thanks.

Related

Trouble with a sub menu in my WordPress menu

I'm creating my first WordPress theme. It's a very simple one for a friend's website, who is a music producer. I'm creating the navigation menu. One of the items on the menu is listen. It's not an actual link. You hover over it and a submenu should appear. So I made Listen a custom link.
The problem is that the submenu doesn't appear. The Submenu has its own class. But I don't think WordPress is reading the CSS
Here is the CSS:
ul.sub-menu {
display: none;
position: absolute;
padding: 0px;
margin-left: -20px;
}
ul.sub-menu li {
display: block;
text-align: left;
background-color: grey;
}
ul.sub-menu li:hover {
background-color: #dae0e6;
}
ul.main_nav li:hover ul.sub-menu {
display: block;
}
Here is the HTML and php code in the header.php:
<nav>
<?php
$defaults = array(
'container' => false,
'theme_location' => 'primary-menu',
'menu_class' => 'main_nav'
);
wp_nav_menu( $defaults );
?>
<!--
<ul class="main_nav">
<li>
Home
</li>
<li>
Bio
</li>
<li>
<a>Listen</a>
<ul class="sub-menu">
<li>Originals</li>
<li>TV/Film</li>
</ul>
</li>
<li>Credits</li>
<li>Contact</li>
</ul>
-->
</nav>
Here is my approach:
I changed css so its shows menu sub menu with CSS.
JsFiddle Demo
nav
{
margin-top:15px
}
nav ul
{
list-style:none;
position:relative;
float:left;
margin:0;
padding:0
}
nav ul a
{
display:block;
color:#333;
text-decoration:none;
font-weight:700;
font-size:12px;
line-height:32px;
padding:0 15px;
font-family:"HelveticaNeue","Helvetica Neue",Helvetica,Arial,sans-serif
}
nav ul li
{
position:relative;
float:left;
margin:0;
padding:0
}
nav ul li:hover
{
background:#f6f6f6
}
nav ul ul
{
display:none;
position:absolute;
top:100%;
left:0;
background:#fff;
padding:0
}
nav ul ul li
{
float:none;
width:200px
}
nav ul ul a
{
line-height:120%;
padding:10px 15px
}
nav ul ul ul
{
top:0;
left:100%
}
nav ul li:hover > ul
{
display:block
}
<nav>
<ul class="main_nav">
<li>
Home
</li>
<li>
Bio
</li>
<li>
<a>Listen</a>
<ul class="sub-menu">
<li>Originals</li>
<li>TV/Film</li>
</ul>
</li>
<li>Credits</li>
<li>Contact</li>
</ul>
</nav>
In example above your menu is commented out. Also parent of ul.sub-menu should be positioned relative.
since you are new ... I think you should start by get general idea about the sub menu and style them in WordPress .
this Tut will help you
http://wproots.com/how-to-style-wordpress-menus-dropdowns/
also I will suggest other option for you .
start form other theme like wordpress deafult theme and edit it
start form starter theme like http://bootstrapwp.rachelbaker.me/
start from template
its hard to build theme from scratch if you are new ... step by step
please assign width to ul like
ul.sub-menu {
display: none;
}
and plaece
ul.main_nav li:hover ul.sub-menu {
display: block;
position: absolute;
padding: 0px;
margin-left: -20px;
top:0;
left:0;
width:800px;
}
just after it

How to add a third level to my CSS drop down menu

I have an existing CSS that only shows a two level menu. I want to add a third level but I'm out of ideas. Could soeone please assist me on what i need to add to the CSS. Below is the current code.
#topnav{
display:block;
float:left;
//width:660px;
margin:0;
padding:0;
list-style:none;
font-size:10px;//was 13
font-weight:normal;
font-family:Verdana, Arial, Helvetica, sans-serif;
color:#FFFFFF;
background-color:#000000;
}
#topnav ul, #topnav li{
float:left;
list-style:none;
margin:0;
padding:0;
}
#topnav li a:link, #topnav li a:visited, #topnav li a:hover{
display:block;
margin:0;
padding:15px 20px;
color:#FFFFFF;
background-color:#000000;
}
#topnav ul ul li a:link, #topnav ul ul li a:visited{
border:none;
}
#topnav li.last a{
margin-right:0;
}
#topnav li a:hover, #topnav ul li.active a{
color:#FFFFFF;
background-color:#059BD8;
}
#topnav li li a:link, #topnav li li a:visited{
//width:150px;
float:none;
margin:0;
padding:7px 10px;
font-size:12px;
font-weight:normal;
color:#FFFFFF;
background-color:#000000;
}
#topnav li li a:hover{
color:#FFFFFF;
background-color:#059BD8;
}
#topnav li ul{
background:#FFFFFF;
z-index:9999;
position:absolute;
left:-999em;
height:auto;
width:170px;
border-left:1px solid #FFFFFF;
border-bottom:1px solid #FFFFFF;
}
#topnav li ul a{width:140px;}
#topnav li ul ul{margin:-32px 0 0 0;}
#topnav li:hover ul ul{left:-999em;}
#topnav li:hover ul, #topnav li li:hover ul{left:auto;}
#topnav li:hover{position:static;}
#topnav li.last a{margin-right:0;}
Here is the HTML
<div id="topnav">
<ul>
<li <?php if($menu== 0) { echo "class='active'"; } ?>>
Home
</li>
<li class="last">
Set Up
<li class="last">
EMR
<ul>
<li class="last" >
Out-Patient
</li>
<ul>
<li>
Registration
</li>
<li>
File Edition
</li>
</ul>
<li>In-Patient</li>
</ul>
</div>
The two sub-menus under out-patient (Registration & File Edition) are not showing.
Thanks.
You need to close a few elements correctly and also the CSS for your solution is:
#topnav li li:hover ul {left: 160px; margin-top: -3em;}
Closed and corrected HTML:
<div id="topnav">
<ul>
<li>Home</li>
<li class="last">Set Up</li>
<li class="last">EMR
<ul>
<li class="last" >Out-Patient
<ul>
<li>Registration</li>
<li>File Edition</li>
</ul>
</li>
<li>In-Patient</li>
</ul>
</li>
</ul>
</div>
Working Snippet
#topnav{
display:block;
float:left;
margin:0;
padding:0;
list-style:none;
font-size:10px;//was 13
font-weight:normal;
font-family:Verdana, Arial, Helvetica, sans-serif;
color:#FFFFFF;
background-color:#000000;
}
#topnav ul, #topnav li{
float:left;
list-style:none;
margin:0;
padding:0;
}
#topnav li a:link, #topnav li a:visited, #topnav li a:hover{
display:block;
margin:0;
padding:15px 20px;
color:#FFFFFF;
background-color:#000000;
}
#topnav ul ul li a:link, #topnav ul ul li a:visited{
border:none;
}
#topnav li.last a{
margin-right:0;
}
#topnav li a:hover, #topnav ul li.active a{
color:#FFFFFF;
background-color:#059BD8;
}
#topnav li li a:link, #topnav li li a:visited{
//width:150px;
float:none;
margin:0;
padding:7px 10px;
font-size:12px;
font-weight:normal;
color:#FFFFFF;
background-color:#000000;
}
#topnav li li a:hover{
color:#FFFFFF;
background-color:#059BD8;
}
#topnav li ul{
background:#FFFFFF;
z-index:9999;
position:absolute;
left:-999em;
height:auto;
width:170px;
border-left:1px solid #FFFFFF;
border-bottom:1px solid #FFFFFF;
}
#topnav li ul a{width:140px;}
#topnav li ul ul {margin:-32px 0 0 0;}
#topnav li:hover ul ul{left:-999em;}
#topnav li:hover ul, #topnav li li:hover ul{left:auto;}
#topnav li:hover{position:static;}
#topnav li.last a{margin-right:0;}
#topnav li li:hover ul {left: 160px; margin-top: -3em;}
<div id="topnav">
<ul>
<li>Home</li>
<li class="last">Set Up</li>
<li class="last">EMR
<ul>
<li class="last" >Out-Patient
<ul>
<li>Registration</li>
<li>File Edition</li>
</ul>
</li>
<li>In-Patient</li>
</ul>
</li>
</ul>
</div>
Please put your third level menu inside parent li, which makes hierarchical order or level of menu
<li class="last" >Out-Patient
<ul>
<li>Registration</li>
<li>File Edition
</li>
</ul>
<li>

Image gallery overlaps php navigation

I have pieced together a PHP navigation for my site with following code:
* {
margin:0;
padding:0;
list-style:none;
text-decoration:none;
}
img {
position: absolute;
top: 10px;
left: 40%;
}
ul#navi {
float:left;
background:#3104B4;
width:97.2%; /* geändert von 150px auf 100% */
border-radius: 10px;
padding: 10px;
margin-left: 10px;
margin-right: 10px;
margin-top: 100px;
font-size: 18px;
}
ul#navi a {
display:block;
padding:0px;
color:white;
font-weight:bold;
border-left: 1px solid red;
text-align:center;
font-size: 25px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
ul#navi li:first-child a {
border-left: 0 none;
}
ul#navi li {
position:relative;
float:left; /* hinzugefügt um eine horizontale Ausrichtung zu erzielen */
width:12.375em /* Hinzugefügt 150px / 16 = 9.375em */
}
/* Alle Ebenen ausblenden */
ul#navi ul ,
ul#navi li:hover ul ul ,
ul#navi li:hover ul ul ul {
position:absolute;
left:-9999px;
background:blue;
}
ul#navi li:hover ul {
background:blue;
}
ul#navi li:hover ul ul {
background:#3104B4;
}
ul#navi li:hover ul ul ul {
background:#3104B4;
}
ul#navi ul {
top:auto; /* Neue Position definiert 16px Schriftgröße + (2 x 5px) padding = 30px / 16 = 1.875em*/
}
/* Einzelne Ebenen einblenden */
ul#navi li:hover ul {
left:0;
background: #3104B4;
}
/* Neuer Deklarationsblock um die Unterpunkte präzise zu positionieren */
ul#navi ul li:hover ul ,
ul#navi ul ul li:hover ul {
position:absolute;
left:100%;
top:0;
}
/* Hover Hinter- und Vordergrundfarbe für alle Ebenen */
ul#navi li:hover > a , ul#navi ul li:hover > a, ul#navi ul ul li:hover > a, ul#navi ul ul ul li:hover > a {
background:#2E64FE;
color:white;
border-left-width: 1px;
}
ul#navi a span {
float:right;
font-weight:normal;
}
<img src="acid.png" alt="logo" />
<ul id="navi">
<li>Home </li>
<li><a class="titel" href="sortiment.php">Unser Sortiment </a>
<ul>
<li>Reiniger </li>
<li>Ungezieferspray </li>
<li>Arbeitsschutz </li>
<li>Thema 4
<ul>
<li>Thema 4.1 </li>
<li>Thema 4.2 </li>
<li>Thema 4.3
<ul>
<li>Thema 4.3.1 </li>
<li>Thema 4.3.2 </li>
<li>Thema 4.3.3 </li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a class="titel" href="aktuelles.php">Aktuelles </a>
<ul id="knoten_3">
<li>Aktionen </li>
<li>Neue Produkte </li>
<li>Sonstiges </li>
</ul>
</li>
<li><a class="titel" href="#kat3">Kontakt </a>
</li>
<li><a class="titel" href="#kat4">Jobs</a></li>
<li><a class="titel" href="#kat4">Impressum</a></li>
</ul>
And now wanted to add this image gallery (dwuser. com/education/content/creating-responsive-tiled-layout-with-pure-css/) on a subpage with the navigation.
Unfortunately the image gallery overlaps with the navigation or doesn't show at all. I tried clear:both but that had no effect.
It seems to me that the positioning of the image gallery is wrong, but I don't know which elements positions I have to change and to what values?
Can anyone point me to a solution?
Also how do i have HTML code start after my PHP-Navigation in general?
With text i used clear:both, but I guess positioning would make more sense?
Thank you
Try adding
ul {
overflow:hidden;
}

Adding Drop-down Menus to the Navigation Bar

I am just a beginner to HTML, CSS, PHP, javaScript.
My drop down menus to the navigation bar is not working.
When I keep the mouse over the links in navigation bar, no drop down menu is apeearing.
Need a help from some one.
CODE
<head>
#menu {
width:1060px;
margin:auto;
padding:0px 0px 0px 0px;
position:relative;
}
#menu ul {
height:25px;
font-size:20px;
font-family:Arial, Helvetica, sans-serif;
font-weight:bold;
text-align:center;
background-color:#8AD9FF;
border-radius:18px;
margin-top:10px;
margin-bottom:5px;
list-style:none;
}
#menu ul li{
border-style:solid;
border-width:2px;
border-bottom:none;
border-top:none;
border-color:#0000FF;
display:inline-block;
text-decoration:none;
color:#FF0000;
padding-bottom:0px;
padding-top:0px;
margin-right:-8px;
}
#menu ul li a {
padding-left:25px;
padding-right:25px
}
#menu ul li a:link{
color:#3366CC;
text-decoration:none;
}
#menu ul li a:visited{
color:#3366CC;
text-decoration:none;
}
#menu ul li a:hover{
background-color:#3399FF;
text-decoration:underline;
}
#menu ul ul {
display:none;
width:125px;
}
#menu ul li a:hover > ul {
margin:0px;
padding:0px;
}
#menu ul li a:hover > ul li {
float:none;
display:block;
}
#menu ul li a:hover > ul li a {
color:#3366CC;
min-width:150px;
}
#menu ul li a:hover > ul li a:hover {
background-color:#3399FF;
text-decoration:underline;
}
#menu ul li {position:relative;}
#menu ul li ul {
position:absolute;
top:30px;
left:0px;
}
</head>
<body>
<div id="menu">
<ul>
<li>Home</li>
<li>College
<ul>
<li>Faculties & Departments</li>
<li>Centres</li>
<li>College Facts</li>
<li>Awards</li>
</ul>
</li>
<li>Education
<ul>
<li>Pahrmacy Law Exam Review Course</li>
<li>Doctor Of Pharm Degree (Pharm. D.)</li>
<li>Graduate Programs</li>
<li>Online MS Programs</li>
</ul>
</li>
<li>Research
<ul>
<li>Medicina lChemistry</li>
<li>Doctor Of Pharm Degree (Pharm. D.)</li>
<li>Graduate Programs</li>
<li>Online MS Programs</li>
</ul>
</li>
<li>Faculty & Staff
<ul>
<li>Faculty Directory</li>
<li>Staff Dierctory</li>
</ul>
</li>
<li>News</li>
</ul>
</div>
</body>
Try something like this :
#menu ul li:hover > ul{
display: block;
}
Try to comment those line here :
#menu ul li ul {
position:absolute;
/*top:30px;*/
left:0px;
}
and :
#menu ul {
height:25px;
font-size:20px;
font-family:Arial, Helvetica, sans-serif;
font-weight:bold;
text-align:center;
background-color:#8AD9FF;
border-radius:18px;
/*margin-top:10px;*/
margin-bottom:5px;
list-style:none;
}
Look at the following code
#menu ul li a:hover > ul {
float:none;
display:block;
}
The above code will display the child levels when they hover the anchor element. But in your code it is a sibling element not child element. So use next sibling element syntax like below.
#menu ul li a:hover + ul {
float:none;
display:block;
}
But after this you have to do so many things to works your menu better way. This will fix the hover display issue only.
DEMO
You can do this without JS or PHP. You have an extra a tag in most of your CSS. You shouldn't show the nested ul when someone hovers over the anchor, you should show it when someone hovers over the list item:
#menu ul li ul {
display: none;
}
#menu ul li:hover ul {
display: block;
}
Likewise, the above style hides the entire nested ul instead of each li, which is cumbersome. Show and hide only one thing: the containing element.
I would recommend some more organization to keep things straight.
instead of writing ul ul{}, it may help you to write ul li ul{}, at least until this code becomes natural to you.
You also have a lot of extra pseudo elements in there. For instance:
#menu ul li a:hover > ul li a:hover {
background-color:#3399FF;
text-decoration:underline;
}
doesn't need the pseudo element :hover on the first a tag (which would be on the li tag anyway). Since you can only see the second a tag on hover, it can have this style all of the time:
#menu ul li ul li a:hover {
background-color:#3399FF;
text-decoration:underline;
}

How to make a link stay active in CSS?

Basically I want the hover-look of a link stay active when you're on that site. I hope I'm explaining this right. There's supposed to be a background behind the link when you're visiting that specific page.
Here's the code for the html:
<div class="menudiv">
<div id="menu">
<ul id="menu">
<li><span>Hem</span></li>
<li><span>Om oss</span></li>
<li><span>Tjänster</span></li>
<li><span>Referenser</span></li>
<li><span> Kontakt</span></li>
</ul>
<div class="clr"></div>
</div>
</div>
And here's the css:
#menu { float:right; padding:23px 0 0 0; margin:0; width:420px; height:35px;}
#menu ul { text-align:right; padding:0; margin:0; list-style:none; border:0; height:35px;}
#menu ul li { float:left; margin:0; padding:0 5px; border:0; height:35px;}
#menu ul li a { float:left; margin:0; padding:10px 0; color:#5c8783; font:normal 12px Arial, Helvetica, sans-serif; text-decoration:none;}
#menu ul li a span { padding:10px 13px; background:none;}
#menu ul li a:hover { background:url(images/r_menu.gif) right no-repeat;}
#menu ul li a:hover span { background:url(images/l_menu.gif) left no-repeat;}
#menu ul li a:active { background:url(images/r_menu.gif) right no-repeat;}
#menu ul li a:active span{ background:url(images/l_menu.gif) left no-repeat;}
Add a CSS class for the that link (eg, <a class="CurrentPage">), then apply the selector to that class (eg, #menu ul li a:active, a.CurrentPage)
As much I know the hover property should put last in CSS (below the active and others) in order to work properly.
you are giving same id :
<div id="menu">
<ul id="menu">
which is wrong
you should make ids different.
What you basically need is to add a css class to the a tag in your menu.
example:
<li><span>Hem</span></li>
add styling to your currenPage class as per the designs you want for that menu item
now, your page should be dynamic for you to be able to set the currenPage css class to the current menu item where the user is currently viewing
example:
<li><a href="?p=start" class="<?php if(/**check if the user is in this link/menu item**/) echo "currentPage"; ?>" ><span>Hem</span></a></li>

Categories