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();
});
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'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/
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 am facing interoperability issues in IE7 and Firefox. li elements height is somewhat more in IE than Firefox.
Here is the attached image for more clarity.
http://img225.imageshack.us/i/interop.jpg/
Code for html and CSS:
<ul class="sa-progress">
<li class="sa-progress-current"><span id="intro_idx" >Select VPN Type</span></li>
<li class="sa-progress-default"><span id="local_idx" >Local</span></li>
<li class="sa-progress-default"><span id="remote_idx" >Remote</span></li>
<li class="sa-progress-default"><span id="vpn_idx" >VPN</span></li>
<li class="sa-progress-default"><span id="remote_dyn_idx" >Remote Users</span></li>
<li class="sa-progress-default"><span id="traffic_idx" >Traffic Profile</span></li>
<li class="sa-progress-default"><span id="review_idx" >Review & Commit</span></li>
</ul>
ul.sa-progress {
color: #333333;
line-height: normal;
padding: 7px 0 10px 10px;
}
ul.sa-progress {
font-size: 12px;
}
Please let me know what am missing here.
Any help would be greatly appreciated.
Thanks
ul/li is one of the more common cross browser differences that crop up as they both have different interpretations of their default rules.
You should look into using a css reset sheet to start off with such as:
http://developer.yahoo.com/yui/3/cssreset/
This will apply consistent base rules to your formatting so that all browsers have a fair chance at matching.
Because you didn't start out with this reset stylesheet and then build your design on top of it you might find that applying it will make several other elements go a bit different when they react to the new defaults. I would say its better to fix these so they look right with the reset sheet and then you will have a consistent baseline to work from.
After that you still might have problems but from the css you have posted I think there are some more parts to it such as the double line spacing you have in some menu items.
If you are going to make these into menu items then a common way that I approach this kind of styling is to make the a tags display: block; and then work my spacings out from that. Try to keep your ul li stylings as lightweight as possible and work with other items you have (such as the container div for the menu and the anchor tags for the links).