slash25 code

  • Home
  • Work
  • Code
  • Github
  • WordPress Austin
  • Blog
You are here: Home / Archives for CSS
July 10, 2012 By Pat · Leave a Comment · (Updated: August 17, 2016)

LESS & WordPress – notes

July 10, 2012 by Pat

Use LESS to build style.less.

style.min.css is mostly a doc-block with an @import bringing in the less.css file.

in functions.php, write a universal body class of the client name. In a group work environment, this could be multiple names.

last, in the style.min.css, @import the client.css where the client is told to place all their custom styles prepended with the custom body class.

Tagged With: CSS, LESS, notes

June 24, 2009 By Pat · 2 Comments · (Updated: August 17, 2016)

Using jQuery to mimic CSS3’s :nth-last-child

June 24, 2009 by Pat

I came across the need for using CSS3’s :nth-last-child pseudo-selector recently. What does this do? Nth-last-child lets you select the nth (2nd, 3rd, 4th, etc) child of some element starting from the last one. For example:

li:nth-last-child(-n+4) //would select the last four list items in a list

To style the 2nd-to-last list item only, this example would work:

li:nth-last-child(-n+2)

The situation I had was there is a list of authors for a site. More than wp_list_authors, it was a custom-generated list of certain users. The list is styled to look like a box with two columns. There are dividers between each author both horizontally and vertically, with the bottom two authors having no bottom divider.

This list:


  • John Doe
  • Hap Pill
  • …(snip)…


  • John Hancock
  • Lorem Ipsum
  • Jane Doe
  • … needs to look like this:

    
    
    • John Doe
    • Hap Pill
    • Foo Bar
    • Ima Doody
    • Chew Bacca
    • John Hancock
    • Lorem Ipsum
    • Jane Doe

    Removing the border on the last list item’s span is easy. Use the :last-child pseudo-selector and the border’s gone.

    #authors li.odd:last-child span {
    border-bottom: none;
    }

    Removing the border on the 2nd-to-last one should be this easy:

    #authors li:nth-last-child(-n+2) span {
    border-bottom: none;
    }

    But for now, that only works in Safari 4. (and maybe Opera?) so how to get that effect in Safari 3 and Firefox 3? (I have not gotten this to work in IE7 or 6. Those are coming.) Use jQuery and a three-line script.

    Here’s what I cobbled together from digging through the jQuery documentation:

    //removes bottom border from next-to-last span in the authors listings
    var $curr = $('#authors li:last');
    $curr = $curr.prev().children('span');
    $curr.css('border-bottom','none');

    The script first locates the last list item. Then it looks for the previous element of that type, then drills down to the children elements that are spans. In this case, there’s only one. Lastly, the script applies a CSS rule of no border to the span.

    Is it perfect? Almost. I’ll need to figure out how to get IE7 and, unfortunately for this job, IE6 to render the next-to-last item correctly.

    Tagged With: CSS, CSS3, jQuery

    copyright © 2020 slash25 code | privacy policy | pat on twitter