I need to change the width of the ul li items, when there is less than 3 li items inside the UL. This is what I created, but it’s not working properly, can you help me fix it?
jQuery(document).ready(function($) {
if ($('ul.products li').length <= 3) {
$($this).css('width', '29%');
}})
The site is http://www.demo.simplexweb.dk/shopdemo1/ . It is related to the section with 3 products. If someone add a new products, the css should be different.
Thanks,
Tom
you can do this with css only like so :
if it’s the first of it’s type and second to last of it’s type that’s means if these two condition are true so there is only two element for this type, then you can apply
width: 50%;
Live Demo
try to add an other
li
element to theul
and the style will not workand this is exactly what you need for your task :
Live Demo
Now you can style the
li's
element inside theul
only if there is less then 3li's
without anyjavascript
EDIT
for less or equivalent to 3
li's
:for less or equivalent to 4
li's
: