SiteCrafting Blah Blah Blog

Oct. 18, 2006 at 10:46am

Navigation Nightmare pt. 1

Something no developer wants to see...

foreach ($left_elements AS $le) {
    ?>
    <table class="leftnav_<?=$le['class']?>">
        <tr>
            <td class="leftnav_<?=$le['class']?>">
                <a href="<?=$le['target']?>" class="<?=$le['theme']?>"><?=$le['name']?></a>
            </td>
        </tr>
    </table>
    <?
}


Nobody wants to see that. Especially not seven different times with seven tiny variants covering seven different if conditions.

Each higher 'class' number is a deeper indentation. Apparently it's necessary for this class identification to be repeated for the table, table cell and link. Converting this to a nested list format (part of my current task) is going to be an adventure.

Well... at least it's indented nicely.

Posted in Coding Techniques, CSS, XHTML by Joe Izenman

Comments (3)

Dave says:

Just having the one class on the table is enough to specify the styles for all items underneath those as well. There's no real reason to go class-happy, it's just excessive.
1 | Oct. 19, 2006 at 1:58pm


That's the sort of thing that makes me groan when I have to edit some of my old code. That, and the fact that I used to indent with spaces. (Now vi's tab size setting is my friend!)

I learned Dave's lesson a few weeks ago when I was setting up the website for I5 Comics. While I was still working on the content side, I anticipated a bunch of classes that I didn't end up needing. Clearing out all the unnecessary attributes later was almost cathartic.
2 | Left by Relsqui | Oct. 25, 2006 at 3:27am


It would be greate to see some examples for code you're placing in post. For easier to what you're talking about

just remark
3 | Left by pchela | Oct. 27, 2006 at 12:42am


Remember me
Name: Email: URL: Comment: *   No HTML, http:// will auto-link
* required    Comment Guidelines