CSS -Test Your CSS Skills #39 - dropdown arrows

CSS - Test Your CSS Skills Number 39 - dropdown arrows: Quiz now ended: Solution in post #32

On my CSS “wishlist” is the “parent selector” that would give you the ability to style the parent of a child using the child as the reference. Or similarly the ability to style a parent element based on the child element that it contains. Alas there is no such thing in CSS - yet.

That’s all well and good but where is that leading us?

In this quiz I will be asking you to perform the above feat in some respects in that I want you to automatically add indicator arrows to show that the item contains a dropdown menu. Essentially if a list element contains a dropdown menu then show an arrow.

It may be easier to look at the attachment first so you can get an idea of what I am talking about.

Are you back yet? Good lets begin.

You can see that the arrow is only showing on elements that contain dropdowns which is a good visual aid and helps differentiate between elements that don’t have dropowns attached.

The puzzle is to add these arrow icons automatically so that if the menu items are changed and flyouts removed or added to different items then the indicator arrows would automatically reflect this change without the need to change any css or html.
Also the arrow should change colour when items are hovered as shown in the attachment.

You can use your own css but the html between the body tags must remain untouched.

Here is the starting code:


<ul id="nav">
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a>
        <ul>
            <li><a href="#">History</a></li>
            <li><a href="#">Team</a></li>
            <li><a href="#">Offices</a></li>
        </ul>
    </li>
    <li><a href="#">Test</a></li>
    <li><a href="#">Services</a>
        <ul>
            <li><a href="#">Web Design</a></li>
            <li><a href="#">Internet Marketing</a></li>
            <li><a href="#">testing</a>
                <ul>
                    <li><a href="#">test 1</a></li>
                    <li><a href="#">test 2</a></li>
                    <li><a href="#">test 3</a></li>
                    <li><a href="#">testing</a>
                        <ul>
                            <li><a href="#">test 1</a></li>
                            <li><a href="#">test 2</a></li>
                            <li><a href="http://www.pmob.co.uk">PMOB</a></li>
                            <li><a href="#">test 4</a></li>
                            <li><a href="#">test 5</a></li>
                        </ul>
                    </li>
                    <li><a href="#">test 4</a></li>
                    <li><a href="#">test 5</a></li>
                </ul>
            </li>
            <li><a href="#">Hosting</a></li>
            <li><a href="#">Domain Names</a></li>
            <li><a href="#">Broadband</a></li>
        </ul>
    </li>
    <li><a href="#">Contact Us</a>
        <ul>
            <li><a href="#">United Kingdom</a></li>
            <li><a href="#">France</a></li>
            <li><a href="#">USA</a></li>
            <li><a href="#">Australia</a></li>
        </ul>
    </li>
</ul>

To save you re-inventing the wheel you can find basic css for dropdowns from the original suckerfish site, or from one of [URL=“http://www.pmob.co.uk/temp/drop-down-basic-good.htm”]my old demos, or perhaps even from Jason’s (Deathshadow) clever [URL=“http://www.cutcodedown.com/codeExamples/menuDemo/template.html”]overflow version.

Rules

There are always rules :slight_smile:

[B]Must work in IE8+ and modern Safari, Chrome, Firefox and Opera (don’t bother with ie7 and under).

Assume that only three levels of menus exist as per the attachment (any more than that is nonsense anyway most of the time).

Remember that the menu order could change and the flyouts added or removed so you can’t rely on sub menus being the third element along or down etc ( e.g. this won’t work li + li + li{}). You must make your code cope automatically.

Valid html and css (css2.1 or 3) (but I am also interested in non valid approaches if its interesting).

No scripts of any kind (unless you want to add support for IE7 and under because you found this quiz too easy).

You can use whatever CSS rules you like but the html must be untouched and no extra elements added.[/B]

I think that covers everything but if anything is still unclear or I have made an error in my logic then just shout. The winner won’t necessarily be the first correct one I receive (but the first entry always gets a big mention and may indeed be the preferred solution).

Remember this is just for fun and there are no prizes. Your reward will be knowing how smart you are.

Don’t post your answers in this thread but PM with the details instead so that all can have a go.

Have fun.:slight_smile:

PS. : In case you missed the other tests you can find them all listed here:

Oh looks interesting, good thing I got a free weekday tomorrow! :smiley:

Nice one!
PM sent :slight_smile:

Wow that was quick I have a correct entry from Remon already (ScallioXTX). Well done Remon:)

Anyone else close yet?

I’m Sure Timo (YuriKolovsky) will have a correct solution soon also :wink:

What the…? that was quick! I have a free day on Wednesday so I definitely give it a try :smiley:

Thanks Nuria :slight_smile:

Whee! I finally managed to crack one of these quizzes (I hope :smiley: ). Solution PMed.

I had an idea for a solution yesterday morning, but got stuck playing shogun2 (damn those addicting games), will post it today after work if it (hopefully) works.

I have correct solutions now from ralph.m and Dresden_phoenix. Well done to both and thanks for taking part.:slight_smile:

You lot are getting too clever now so I’ll have to think up something more dastardly next time :slight_smile:

Anyone struggling? I’ll give hints in a couple of days if you are.

Unlike some of my other quizzes this one will produce a useful snippet of code that you can add to your own dropdown menus by default and automate the process of adding arrow indicators where needed.

Yes, I was thinking I’d be able to use this in real world examples from now on. Nothing really lost if older browsers don’t support it.

done :slight_smile:
the method I thought of initially worked just fine.

p.s. don’t bother with ie7 and under gives it away :stuck_out_tongue:

Well done Timo I knew you would do it :slight_smile:

If you wanted an extra challenge you could add an “expression” for IE7 and under to mimic the CSS method.

I really don’t like expressions, I would rather make it work with bare javascript.

Normally i’d say yes but if you use a once only expression then it can be quite neat. See this thread for a good example.

We have another correct solution form CletusSpuckler (Johan) so well done and thanks for
taking part :).

Good to see that we have some proficient coders in the forum and thanks to all that took part. The quiz will stay open until the weekend and then I have a another little one to post for next week to keep the momentum going.

what!? there are once-only expressions?

I got it… but then I don’t have it… I got it working but I need to work out how to let those arrows at the top always visible!

I think that I’m going to read DS60’s overflow method and see if I can work it out using some other technique.

lol - you won… and then you lost :slight_smile:

See here for more info.

completely… but hey, it is another way to say that I obviously didn’t follow the right approach.