I've managed to put a great looking menu togheter!`
<li class="huvudmenu">Framsida</li>
<li class="huvudmenu">
<a>Om oss</a>
<ul>
<li>Styrelsen</li>
<li>Historik</li>
<li>Stadgar</li>
<li>Topeliuspriset</li>
<ul>
<li>HTML</li>
<li>CSS</li>
</ul>
</li>
</ul>
</li>
<li class="huvudmenu">Verksamhet
<ul>
<li>Hangö seminariet</li>
<li>Årsberättelser</li>
</ul>
</li>
<li class="huvudmenu">Estholmen</li>
<li class="huvudmenu">Bli medlem</li>
`http://jsfiddle.net/hx6uvc19/ The setup I have does not, unfortunatley, work very well on touch screen devices. Is there any way I can keep the design while making it touch screen compatible?
Thanks!
You can not use the :hover pseudo class on mobile. In order to get this effect you can use JQuery as stated by #jbutler483 in the comments.
If you wanted to do this you could do it by adding an .active class to the main li's (By using the class .huvudmenu) on click/touchstart and add this to the css where you have your hover styles as well.
This is the JQuery:
$('.huvudmenu').on('click touchstart', function(e){
e.preventDefault();
$(this).toggleClass('active').siblings().removeClass('active');
});
and the styles to add are:
nav ul li.active > ul {
display: block;
}
and
nav ul li.active:after {
width: 100%;
background: #404040;
}
this will then allow the styles on click and touchstart events. If you wanted this to only run on mobile you could just remove the click and use touchstart events and/or put some kind of detection that this is a mobile device before initialising the JQuery function.
Here is an update to your fiddle: http://jsfiddle.net/lee_gladding/hx6uvc19/3/
Related
Please help solve the problem, because my ideas have been exhausted...(
I have a :
<nav class="nav_editor" ng-show="status.editorMenuOn">
<ul class="menu_editor">
<li class=""><a ng-href="/articles/user/{{ status.userID }}">My Articles</a></li>
<li class="">Create Article</li>
<li class="">Comments</li>
</ul>
</nav>
And a CSS classes:
.menu_editor li a {
color: rgb(125,125,125);
font-size: 1.25vw;
margin-right: 20px;
text-decoration: none;
}
I want to make highlighting the item in the menu when this page is active (not pseudo ":active"), just when someone watching current page, for example "My Articles".
I have tried about 3 variants by CSS/HTML only, JavaScript and jQuery, but it is either not working properly or not working at all.
Please help solve this problem.
Thank you in advance!
When the myArticle page loads, just do jquery addClass method.
$(document).ready(function(){
//remove highlighted menu buttons on pageload
$(".menu_editor li").removeClass("activeMenuItem");
//add class only to the specific one
$(".foo").addClass("activeMenuItem");
});
I have following code for the Menu in wordpress:
<div class="menu-about-container">
<ul id="menu-about-1" class="nav-menu">
<li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-574">Our History</li>
</ul>
</div>
I want to give display:none to Our History.But want something like if it is child of menu-about-1 and menu-about-container then and then give display:none.
How can I do it?I know its very silly but I don't have any designing experience.So can any one guide me ?
Use standard CSS selectors to hide any menu item that is a child:
.menu-about-container #menu-about-1 li.menu-item { display: none; }
If that particular item is always menu-item-574 and you want to hide that one, only, use:
.menu-about-container #menu-about-1 li.menu-item-574 { display: none; }
if you only want to hide Our history you can use
#menu-about-1 li{display: none}
But that will hide al the list items so if you want to add others in the future, and you only want to hide the fist one you should use
#menu-about-1 li:first{display: none}
Add this to you css rules:
.menu-about-container > #menu-about-1 > li {
display:none;
}
The > targets the immediate child of the previous selector.
See fiddle here: http://jsfiddle.net/3xLZu/7/
Got a nice little CSS3/HTML5 hover menu going here... and from what I've tested, it works fine on my Windows PC in recent IE/Firefox/Chrome/Opera builds... and on Safari in my iPad2 Mini. Seems to be OK on cruddy Azpen Android tablet, AFAIK. (Still feel free to critique/optimize it though, fairly new to HTML5/CSS3.)
Still, I have a curiosity regarding the behavior in iOS/Safari... first some of the code snippets that I think are most relevant (but the grand bulk is in the fiddle):
<li>Foo </li> <!-- anchor allows click/hover states -->
<li>Bar
<ul>
<li>Bar 1
</li>
<li>Bar 2
</li>
<li>Bar 3
</li>
<li>Bar 4
</li>
</ul>
</li>
<li>Qux</li> <!-- won't react to hover/click on iOS -->
And the bit of CSS that lets the submenus display:
/* on hover, color background */
nav li:hover
{
color: white;
background: rgba(123,255,0,.35);
}
nav li li { display: none; } /* suppress sublist entities*/
nav li:hover li { display: block; } /* until main list hovered over */
Now to my problems/questions...
Is there a better work-around (less hack-y) way to implement hover state to work on iOS, without forcing anchors on all list items? I only noticed the issue when I had opted to remove links from the main menu list...
The other matter is regarding the hover state "sticking." Is there a way to unclick/unhover in my CSS so that the menus don't stay up indefinitely? It's OK for the menus to be up if you want to click a submenu item, but if you want to zoom out, click away, browse eleswhere, the submenus stay active, displayed, and hide any content directly below it.
Preferably, I would like to keep the page/content with just CSS/HTML. Thank you.
Got help earlier on how to get this collapsing menu to work. But now all of a sudden the links in it won't work. they just contract the the menu again. Any ideas?
Thanks a lot!
CSS:
#list, .show {display: none; }
.hide:focus + .show {display: inline; }
.hide:focus { display: none; }
.hide:focus ~ #list { display:block; }
#media print { .hide, .show { display: none; } }
li.folding {list-style-type:none; margin-left:-20px;}
HTML:
<div>
[Link]
[Link]
<ol id="list">
<li class="folding">Item 1</li>
<li class="folding">Item 2</li>
<li class="folding">Item 3</li>
</ol>
</div>
Your code works fine as it is..
Working JSFiddle. ( IN FIREFOX ONLY ! )
The problem is more browser compatibility, run the JSFiddle in firefox and it will work as you expect, on chrome and safari it does not work.
The better solution for this (for all browsers), is to use Javascript/jQuery to hide and show the menu on click of a button, this will work across all mobiles, tables & browsers consistently with minimal code.
Update
Here is a quick example of getting this working using jQuery. You can see the code is very small, easy to read and extend, and will also work on ALL browsers!
VIEW THE JSFIDDLE
HTML:
<div>
[Link]
<ol id="list">
<li class="folding">Item 1</li>
<li class="folding">Item 2</li>
<li class="folding">Item 3</li>
</ol>
</div>
Javascript/jQuery:
// When the page is loaded and ready
$(function(){
// On click of `.toggler` (the <a> with class `.toggler`)
$('.toggler').click(function(){
// Toggle the list menu (toggle means if hidden show it, else hide it)
$('#list').fadeToggle(); // also try.. `slideToggle()`
});
});
The above HTML & Javascript does exactly the same thing, except it will work on all devices!
View the JSFiddle - Javascript/jQuery Version
Since clicking another link makes the first one loose focus, the items in the list go back to hiding.
Since the focus loss is always done before executing the click behaviour, the click does not reach the link since it is not under your mouse anymore.
I have a menu bar which uses the below code, when the title list items are clicked they call the showHide function to change the class of the inside list to one with display block instead of none.
On ie6 and ff it works fine, chrome opera etc etc. But on ie7 the inside list is render under the other elements in the main list. Everything i try seems to break on of the other browsers.
Any help much appreciated.
<ul id="FOOMENU" style="list-style-type: none; padding-left: 10px; text-decoration: none;">
<li class="navItemsHeader"><b>View by..</b></li>
<li>
<b><a style="text-decoration:none;" href="javascript:void(0);" onclick="showHide('foobarMenu');">foobar..</a></b>
</li>
<li id="foobarMenu" class="hideMenu">
<ul style="list-style-type:none; padding-left:10px; text-decoration:none; ">
<li>DYNAMIC LIST OF LINKS HERE.</li>
</ul>
</li>
I would get to grips with a javascript library like jQuery, as it will take care of all the cross-browser issues for you, and has such useful methods as toggle() to show and hide elements.
The jQuery code would be something like
$(".hideMenu").click(function() {
$(this+"> ul").toggle();
});
Also, if you wanted to hide previously shown submenus you would use this:
$(".hideMenu").click(function() {
$(".hideMenu > ul").hide();
$(this).children("ul").show();
});