Forcing <ul> levels to display in separate panels - html

I've got a 3-level menu generated by CMS (Joomla to be exact), which looks something like this:
<ul class="nav menu">
<li class="item-108">1-level-1</li>
<li class="item-124">1-level-2</li>
<li class="item-125 active deeper parent">1-level-3
<ul class="nav-child unstyled small">
<li class="item-164">2-level-1</li>
<li class="item-165">2-level-2</li>
<li class="item-166 current active deeper parent">
2-level-3
<ul class="nav-child unstyled small">
<li class="item-212">3-level-1</li>
<li class="item-213">3-level-2</li>
</ul>
</li>
<li class="item-210">2-level-3</li>
<li class="item-211">2-level-4</li>
</ul>
</li>
<li class="item-126">1-level-4</li>
</ul>
What I need is to force it to behave like a menu for example from this site: http://wachtel.de/backoefen/etagenoefen.html - I mean display every nested level in a separate box under it's parent.
I'm having trouble achieving it in pure CSS, so before I loose my mind, I'd like to ask you: Can it even be done, or do I need to use JS?
EDIT:
So far I've tried to make the prime UL relative and sub-ULs absolute with "left: 0" and "width: 100%", but it doesn't seem to work.
EDIT2:
Problem was caused by bootstrap.css property .nav > li {position: relative}, which was ruining the layout.

All you need in your case is some positioning. Position the .nav relatively, then you can absolutely position the .nav-childs accordingly. I inserted a minimal example for you - I'm sure you can figure out the hide/show stuff on hover by yourself.
.nav.menu{
position:relative; /* positioning the base element*/
}
li{
float:left; /* aligning the list node */
/* the rest is presentational stuff: */
list-style:none;
background-color:#ddd;
border:1px solid #aaa;
}
li a{
text-decoration:none;
}
.nav-child{
/* the important part:*/
position:absolute; /* absolute positioning*/
left:0; /* left according the the root element*/
/* the top positioning stays untouched! */
}
<ul class="nav menu">
<li class="item-108">1-level-1</li>
<li class="item-124">1-level-2</li>
<li class="item-125 active deeper parent">1-level-3
<ul class="nav-child unstyled small">
<li class="item-164">2-level-1</li>
<li class="item-165">2-level-2</li>
<li class="item-166 current active deeper parent">
2-level-3
<ul class="nav-child unstyled small">
<li class="item-212">3-level-1</li>
<li class="item-213">3-level-2</li>
</ul>
</li>
<li class="item-210">2-level-3</li>
<li class="item-211">2-level-4</li>
</ul>
</li>
<li class="item-126">1-level-4</li>
</ul>

Related

How to keep <li> elements on single line in fixed width?

I am developing a website and I want a menu like the above image. This is what I have tried: jsFiddle
HTML
<div class="">
<ul class="header-menu-ul">
<li class="header-menu menu-link1-color">ABC's Office</li>
<li class="header-menu menu-link2-color">Benefits</li>
<li class="header-menu menu-link3-color">NEW Brand</li>
<li class="header-menu menu-link4-color">Editorial</li>
<li class="header-menu menu-link5-color">Manger</li>
<li class="header-menu menu-link6-color">Extra</li>
</ul>
</div>
The problem I'm facing is it's taking a space between <li> tags.
I just floated the list items to the left, like this:
.header-menu-ul li {
float: left;
}
WORKING FIDDLE: link.
DEMO
This will create an always single line menu unliek the floating solution where often items fall from position on small sizes + no spaces between the items.
Code:
.header-menu-ul{
display: table;
width: 100%;
}
.header-menu{
display: table-cell;
}
my approach would be using inline-block and min-width. can also use percent in width (1oo% / total_li ).

Write slightly different CSS for Parent Menu Item

everybody!
Got into a bit of a trouble here.
So, basically, I badly want to make my Parent Menu Items in Joomla! main menu slightly different then other Menu Items. What I want to achieve is that the Parent Item would have ... let's say, a little triangle made with bg image on the right to show visitors there are some submenus included.
I've been trying to get my CSS working, but somehow nothing happenes and with inspecting the generated code and elements CSS hasn't applied anything to the Parent Items.
Here's the code:
<li class="item-101 current active"><a href="/" >Domov</a></li>
<li class="item-107"><a href="/index.php/o-meni" >O meni</a></li>
<li class="item-108 deeper parent"><a href="/index.php/psihoterapija" >Psihoterapija</a>
<ul class="nav-child unstyled small">
<li class="item-113"><a href="/index.php/psihoterapija/podmeni-1" >Podmeni 1</a></li>
</ul>
</li>
<li class="item-109"><a href="/index.php/zdravstvena-psihoterapija" >Zdravstvena psihologija</a></li>
<li class="item-114 deeper parent"><a href="/index.php/ponudba" >Ponudba</a>
<ul class="nav-child unstyled small">
<li class="item-117"><a href="/index.php/ponudba/podmeni-2" >Podmeni 2</a></li>
<li class="item-118"><a href="/index.php/ponudba/podmeni-3" >Podmeni 3</a></li>
<li class="item-119"><a href="/index.php/ponudba/podmeni-4" >Podmeni 4</a></li>
</ul>
</li>
<li class="item-139 deeper parent"><span class="nav-header">Ostalo</span>
<ul class="nav-child unstyled small">
<li class="item-138"><a href="/index.php/ostalo/aktualno" >Arhiv novic</a></li>
<li class="item-116"><a href="/index.php/ostalo/povezave" >Povezave</a></li>
<li class="item-115"><a href="/index.php/ostalo/kontakt" >Kontakt</a></li>
</ul>
</li>
So, the items I want to change are those with .deeper.parent class.
The CSS code I wanted to apply but doesn't work:
#navigation .parent {
padding:37px 22px 37px 8px !important;
background-image: url(../images/more.png) !important;
background-position: right !important;
background-repeat: no-repeat !important;
}
I also tried changing #navigation .parent to #navigation .deeper.parent and to #navigation li.item-108.deeper.parent as well. Nothing really works. Any ideas? Thanks!
I'm assuming some coding here for display purposes, but what you want here is this part:
#navigation li.parent { padding:37px 22px 37px 8px !important; background:url(http://upload.wikimedia.org/wikipedia/commons/f/f7/Arrow-down-navmenu.png) no-repeat right center}
You can see fiddle and the adjust at will (REMEMBER: I'm assuming your code so you'll have to adjust it to your real code!)
Firstly, ensure you actually have the #navigation ID assigned to your <ul> like so:
<ul id="navigation">
Secondly, make sure you do not target menu items based on their item number, such as .item-108. These are assigned by Joomla and may change in the future.
Ok, so as you mentioned, you want to target menu items with the deeper and parent classes, for this, you can use the following:
.deeper.parent a {
background: url(../images/more.png) no-repeat;
background-position: right center;
height: 12px;
}
Note that I have used right center to define the X and Y axis, and also defined the height of the image, which may be different for you.
Hope this helps

CSS puzzle: move last two item of the navigation to the right

I have a horizontal navigation, and I want the last two item to be pushed to the right side of the container.
With only one item, I could simply float the last item of the navigation. But I want to apply this to two elements - and I have the constraint that their order has to be the same in HTML and for the viewer.
I tried the following, but this broke my javascript code which relies on
$('... a').parent().next().doSomething(...)
The code
<ul class="main main-nav">
<li class="first">Projekte</li>
<li>Aktuell</li>
<div class="push-right">
<li>Über uns</li>
<li>Kurse</li>
</div>
</ul>
Is there some obvious solution I don't see?
Any other shortcut?
You shouldn't place a div inside of a ul:
<ul class="main main-nav">
<li class="first">Projekte</li>
<li>Aktuell</li>
<li class="push-right">Über uns</li>
<li class="push-right">Kurse</li>
<!-- Or Flip them to maintain order -->
<li class="push-right">Kurse</li>
<li class="push-right">Über uns</li>
</ul>
CSS:
.push-right{
float:right;
}

Wordpress add class to menu work working with my theme

I am using a WordPress theme called 'Wordpress Foundation v2 by 320press'
I am using the custom menus within the WordPress dashboard, I want to add a class to the 'li' to change the styles of the sub menus:
For Example:
About Us - will have a sub menu of four sublinks, therefore i want to add a class to that submemu called .fourNav which will then set each 'li' a with of 25%.
Then Customers - will have 2 sub links, so i want to add a class called .twoNav to each 'li' which will have a width of 50%.
I also want to add another class on top of these for each 'li' that will have a background image to each 'li'.
The Wordpress menu allows you to add classes and a description which will be displayed in the menu, but when i inspect the element the classes are not getting applied.
However when i add the class manually within the DOM it picks up the CSS and works.
How can i add the menu system to its full ability within this theme?
This is what im doing, but its not adding the class on:
http://thesis-blogs.com/add-a-custom-class-to-each-item-in-the-wordpress-menu/
So what i think i need is a snippet of php to allow the menu system to work with my theme. As when i add in the class in the dashboard my theme doesnt apply it.
This is the code that gets outputting in the html: -
<ul id="menu-main-nav" class="top-nav nav-bar hide-for-small">
<li id="menu-item-5" class="has-flyout active">
Home
<ul class="flyout" style="display: none;">
<li id="menu-item-50">sub menu four</li>
<li id="menu-item-51">sub menu three</li>
<li id="menu-item-52">sub menu two</li>
<li id="menu-item-53">sub menu one</li>
</ul>
</li>
</ul>
you have to edit the template code directly...
i think the menú is in
worpressdir/wp-content/themes/yourthemename/header.php
in order to edit this correctly you will need a medium skills with PHP and html. good luck
Go to Appearance -> Menus -> Screen options - then the following
As far as I understood from your requirements this is how it should work:
1. When you hover over a menu item, it should get a new class name.
2. When you hover over a sub-menu item, both the sub-menu item and the parent element of the corresponding sub-menu item should get a new class name.
If this is what you want checkout this jsfiddle. I have used jquery for this. Check if this helps you.
HTML:
<ul class="menu-bar">
<li class="menu-block">Menu 1</li>
<li class="menu-block">Menu 2
<ul class="sub-menu-block">
<li class="sb-menu-list">Sub Menu</li>
<li class="sb-menu-list">Sub Menu</li>
<li class="sb-menu-list">Sub Menu</li>
</ul>
</li>
<li class="menu-block">Menu 3</li>
<li class="menu-block">Menu 4</li>
<li class="menu-block">Menu 5</li>
</ul>
CSS:
.menu-bar{
background-color:blue;
width:100%;
display:inline-block;
}
.menu-bar > li{
display:inline-block;
position:relative;
}
.sub-menu-block{
display:none;
position:absolute;
top:20px;
padding-left:0;
width:75px;
padding:10px 3px;
background-color:#ccc;
}
.menu-bar > li:hover .sub-menu-block{
display:block;
}
.sub-menu-block li{
list-style: none;
display:block;
padding: 4px 0;
}
.sub-menu-block li:hover{
background-color:red;
}
JQuery
$(function(){
$(".menu-block").on("mouseover",function(){
$(this).addClass('hovered');
});
$(".menu-block").on("mouseout",function(){
$(this).removeClass('hovered');
});
$(".sb-menu-list").on("mouseover",function(){
$(this).addClass('child-hovered');
$(this).parents(".menu-block").addClass('parent-hovered');
});
$(".sb-menu-list").on("mouseout",function(){
$(this).removeClass('child-hovered');
$(this).parents(".menu-block").removeClass('parent-hovered');
});
});

Image after Nav List that is using affix in Bootstrap

I am trying to affix an image to the bottom of a nav list and have it stay there when the page scrolls.
This is what I am wanting:
This is what I am getting when the affix kicks in:
I need it to stay just like picture one. I have tried googling the problem and searching stack overflow with no results.
Here is the code:
<!--SIDEBAR NAVIGATION -->
<ul class="nav nav-list well hidden-phone hidden-tablet" data-spy="affix" data-offset-top="850">
<li class="nav-header">The Green Panda</li>
<li class="divider"></li>
<li>What We Do</li>
<li class="divider"></li>
<li>Our Solutions</li>
<li class="divider"></li>
<li>More Than Web Design</li>
<li class="divider"></li>
<li>Contacting Us</li>
</ul>
<img src="img/woody-effect.png" class="img-bottom nav-list" data-spy="affix" data-offset-top="850">
EDIT:
The selector was incorrect.
If the height of your menu is static, you can add a class to that image when it switches over to the fixed styling and apply this css:
top: 310px;
That will position it at the bottom of your menu.
I would set up a class underneath .affix and have it applied to your image (add the id panda_logo)
#panda_logo.affix {
top: 310px
}