Project

General

Profile

Is it possible to get Finer control over menu items?

Added by Jeff Flesher almost 11 years ago

Currently setStyleClass only sets the ul tag, I need to set the class for each element in the menu, meaning I need to change all 3 tags: ul, li and "a" tag, so I can create a menu system with sub menus that drop down on fly over.

I want to use it in the Navigation Bar, but I don't want to use a lot of Drop downs that you have to click on, I want them to drop down on fly over, and I do not see anything like that in Bootstrap, but I already have a style sheet I made years ago that still works great, not sure what to call it, its kind of a deviation of a suckerfish css menu, you can see it at one of my web sites ([[http://lightwizzard.com/]]) that I am trying to port over to Wt.

Maybe there is a way to change the behavior of the Popup so it opens on fly over, and that will be the best I can do, so do you know how to do that.

Menu systems are so important to any web site, I like the suckerfish menus, because they are more like menus in an Native App, it would be great to be able to use a suckerfish menu, I wish bootstrap had one, maybe I can find one that does not require all 3 menu tags (ul, li, a), but its looking like the only tag I have control over the the ul tag, so I could use a menu like Son of a Suckerfish

[[[http://www.htmldog.com/articles/suckerfish/dropdowns/]]]

because it only uses the ul tag, put its not as nice as mine, since it requires Javascript, mine is pure css, and was written, for both Horizontal or Vertical, on the same page, and does not change any ul tags in the same document, but it does require control over every elements class.

Adding support for other menu libraries would be great, but this is not a feature request, I just want to know if anyone knows how to set the class for each menu elements class (ul, li, a), so then I can work on integrating these other menu libraries into Wt, so everyone can benefit from it.

Here is a example of a menu system I am working on, I am not to happy with the submenu or popup, but unsure how to set each element, I may have to write a menu function to create the markup, so I might update this for those interested, it would be easy enough, but I would first like to rule out getting the menu functions to work the way I need them to, so if anyone has any idea how to set each element.

Example of HTML for menu:

<div class="sfmenumodhorz">
    <ul class="sfhmenu">
        <li class="selectedmm">
            <a class="selectedmm" href="/home.html">Home</a>
        </li>
        <li class="mainmenumm">
            <a class="mmwc" href="/submenus/0.html">Sub-Menus</a>
            <ul class="sfhmenu">
                <li class="submenumm">
                    <a class="smwc" href="/submenus/1.html">Sub-Menu-1</a>
                        <ul class="sfhmenu">
                            <li class="submenumm">
                                <a class="smwc" href="submenus/2.html">Sub-Menu-2</a>
                                <ul class="sfhmenu">
                                    <li class="submenumm">
                                        <a class="submenumm" href="/submenus/3.html">Sub-Menu-3</a>
                                    </li>
                                </ul>
                            </li>
                        </ul>
                </li>
            </ul>
        </li>
    </ul>
</div>

The css is open source based on a pure css suckerfish style menu

Orientation: sfmenumodhorz or sfmenumodvert, sfhmenu or sfvmenu

Selected: selectedmm

Submenu: submenumm

Submenu with Children: smwc

Source code for example:

wittywizard.org/resources/Sub-Menu.zip

Thanks

Jeff Flesher


Replies (8)

RE: Is it possible to get Finer control over menu items? - Added by Alex V almost 11 years ago

you can use SetStyleClass on a WMenuItem to set the style of the li elements.

for the nested you can use css selectors to on direct children of the li elements.

myMenu~~itemAt(0)~~>setStyleClass("mystyleclass");

RE: Is it possible to get Finer control over menu items? - Added by Jeff Flesher almost 11 years ago

Thanks for the reply.

I updated my example, and did not find that

you can use css selectors to on direct children of the li elements.

myMenu~~itemAt(0)~~>setStyleClass("mystyleclass");

it only changed the li element.

So far the tag is the only element I can not change.

This example has to types of menus:

define DO_POPUP -> WPopupMenu

else WSubMenuItem

The WPopupMenu has a strange behavior that I have to click twice on Menu-3 to make it active.

Source code for example:

wittywizard.org/resources/Sub-Menu.zip

Thanks for any help.

RE: Is it possible to get Finer control over menu items? - Added by Alex V almost 11 years ago

I don't think I was quite clear before. I don't believe there is a direct way to style an tag in the menus

But you can target them with a css selector that targets the child tags of the

you have applied a custom style to.

ie:

myMenu~~itemAt(0)~~>setStyleClass("toStyleA");

.toStyleA > a

{

...

}

RE: Is it possible to get Finer control over menu items? - Added by Jeff Flesher almost 11 years ago

Now I get it, thanks, using css selectors is a great idea.

RE: Is it possible to get Finer control over menu items? - Added by Jeff Flesher almost 11 years ago

For some reason I can not get this to work, I know the css Selectors work on the top level, but not in the nested levels, I am not that good with css, does anyone know how to fix this.

It would be so much easier if Wt had a way to change the tag class.

I updated the Source code for example:

[[[http://wittywizard.org/resources/Sub-Menu.zip]]]

RE: Is it possible to get Finer control over menu items? - Added by Wim Dumon almost 11 years ago

Jeff,

I think you can either call setStyleClass for your nested menus too, or you can use a more general selector, like:

.toStyleA > a {
...
}

with myMenu->setStyleClass("toStyleA");

Then all anchors in your menu will be styled by this rule.

BR,

Wim.

RE: Is it possible to get Finer control over menu items? - Added by Jeff Flesher almost 11 years ago

I posted my example to: [[[http://wittywizard.org:8080/ww]]]

the css is here: [[[http://wittywizard.org:8080/resources/themes/wittywizard/blue/SfMenuHoriz.css]]]

If you click on any menu but Menu-2 this works, you see the down arrow:

.selectedmmwc > a

{

color: #FFEE02;

background-color: #2139C4;

background-image: url(Images/sprite.gif);

background-position: 0 --2734px;

background-repeat: no-repeat;

}

If you click on Menu-2 -> SubMenu-1 you will note that the main menu item for Menu-2 works (somewhat, the image url does not work for some reason)

the ul has the class: "activemmwc dropdown"

even though in the code I removed the dropdown class: myPopupMenu[menu.path_]->removeStyleClass("dropdown");

this is true of nav also, so not sure why this function fails to remove the class

now the li for SubMenu-1 class is selectedsm

but this does not work:

.selectedsm > a

{

color: #FFFFFF;

background-color: #FF0000;

}

This is driving me crazy, its like something is stepping on the CSS.

I can set the class with setStyleClass for the ul and li, but not the , that just a very limited functionality.

This would be so much easier if I could just change the class of the , instead of trying to get selectors to work right.

Thanks for any help.

Jeff Flesher

Solved somewhat: Is it possible to get Finer control over menu items? - Added by Jeff Flesher almost 11 years ago

I did find a workaround the css issue.

It would be better if I could change the

But for now this works, it will be posted in Witty Wizard at Git Hub.

Thanks

    (1-8/8)