4

I'm working on translating a site from HTML/CSS to Wordpress, and I've come across an issue. In the spirit of keeping the site fully customizable from the dashboard, I've been using Wordpress' default menu system for creating my navigation, but I can't get it to do what it would in hard coded HTML. I need to move the parent list item (parent's a element) below it's child ul as shown below:

<li id="generalinfo">
    <ul>
        <li><a href="#">About the Festival</a></li>
        <li><a href="#">History</a></li>
        <li><a href="#">Sponsors</a></li>
        <li><a href="#">Contact Us</a></li>
    </ul>
    <a class="cat" href="#">General Info</a>
</li>

But by default, Wordpress forces it to do this instead:

<li id="generalinfo">
    <a class="cat" href="#">General Info</a>
    <ul>
        <li><a href="#">About the Festival</a></li>
        <li><a href="#">History</a></li>
        <li><a href="#">Sponsors</a></li>
        <li><a href="#">Contact Us</a></li>
    </ul>
</li>

It is vital for the design that the link come after the unordered list, as it will be a descending banner like this:

https://i.sstatic.net/zrcgJ.png

The graphic elements are background elements with hover states. This is what they would look like dropped down, the home button on the left is an example of the banner fully raised. This is why it's important to have the parent link element displayed at the end.

Ideas?

7
  • 1
    Very interesting problem. I guess you have to use a custom walker and build a custom method display_element().
    – fuxia
    Commented Feb 4, 2013 at 23:58
  • 1
    Is the parent link the icon? Why can't you use absolute positioning and bottom padding to do this? Commented Feb 5, 2013 at 1:18
  • 1
    This is an interesting problem but +1 on @sanchothefat looking for a CSS way to do this. Playing with source order like this is an invitation for accessibility problems.
    – mrwweb
    Commented Feb 5, 2013 at 1:20
  • @sanchothefat Yes, the parent link is the icon, but absolute positioning wouldn't work correctly as the banners move from a hidden position, revealing the children. The position needs to be relevant to the banner itself, not the page. It would fail to render correctly in some browsers. Commented Feb 5, 2013 at 1:40
  • @DustinArmstrong elements are positioned absolutely according to the nearest parent with position: relative; so you'd only have make the banners position: relative; for it to work Commented Feb 6, 2013 at 10:48

2 Answers 2

0

Since this is a stylistic change, and not looking to reorder the DOM for semantic reasons, I think the js solution wouldn't be the best approach. Better to keep it in CSS, keeping the markup intact.

Two ways to do it:

Flexbox:

#generalinfo{
  display: flex;
  flex-direction: column-reverse;
}

CSS Grid:

#generalinfo{
  display: grid;
}

.cat{
  grid-row: 2;
}
1
  • Since the browser support of Flexbox has radically changed since I wrote this, I would likely use this solution now. This is the most accessible option for screen-readers and requires no change of markup arbitrarily. Thanks! Commented Jun 28, 2021 at 13:39
0
$(".cat").each(function(){
    $(this).appendTo($this.parent(".li"));
    $(this).remove();
}
);

Should do the trick. As far as accessibility is concerned, most modern crawlers (read Googlebot) will process and crawl this as it doesn't involve a trigger to process (see - http://www.thoughtspacedesigns.com/blog/search-engine-optimization/whats-this-googlebot-processes-javascript/). Much more fluid for the sake of keeping with responsive design. I avoid absolute positioning like the plague for most purposes (unless contained in a position:relative container).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.