I have a basic gallery set up using an unordered list.
<h1>Projects</h1>
<hr>
<!-- Projects displayed as an unordered list -->
<ul class="gallery">
<li class="item residential">
<img src="Projects/01-HighTorEast-EarlShilton/01-thumbnail.jpg" width="212" height="119" alt="High Tor East, Earl Shilton">
<h2><a class="info" href="Projects/01-HighTorEast-EarlShilton/info.php">High Tor East, Earl Shilton</a></h2>
<h3><a class="cat" href="residential">Residential</a></h3>
</li>
<li class="item modernisation">
<img src="Projects/02-Hollycroft-Hinckley/02-thumbnail.jpg" width="212" height="119" alt="Hollycroft, Hinckley">
<h2><a class="info" href="Projects/02-Hollycroft-Hinckley/info.php">Hollycroft, Hinckley</a></h2>
<h3><a class="cat" href="modernisation">Modernisation & Domestic Extensions</a></h3>
</li>
<!-- More project items follow... -->
</ul>
</section>
In my CSS, I adjusted the right margin value to zero for every fourth child of the .item class. This was done to display four items in a row on the page without removing margins, which would only fit three items per row.
ul.gallery { clear:both; list-style:none; margin:0; padding:0; width:940px; }
.gallery a:hover { text-decoration:underline; }
li.item { display:inline; margin:30px 20px 30px 0px; padding:0px; height:178px; width:220px; float:left; background:#ededed url('../Images/featuredline.png') repeat-x 0% 100%; overflow:hidden; }
li.item:nth-child(4n+4) { margin:30px 0px 30px 0px; }
Additionally, I implemented a small jQuery script to sort items based on category. Clicking on a specific category link will hide elements with different categories.
$('.cat').bind('click', function(e) {
var cat = $(this).attr('href');
$('.item').each(function () {
var itemClass = $(this).attr('class');
if (itemClass != 'item '+cat) {
$(this).css({"display":"none"});
};
});
e.preventDefault();
One challenge I encountered is that the CSS property .item:nth-child still counts elements with a display property set to none after sorting them with the jQuery script. I am uncertain how to resolve this issue. I need the .item:nth-child property in CSS to count only visible elements after applying the jQuery filter.
You can view the website here.