Building a Client Logo Grid with Centered Elements

Building a Client Logo Grid with Centered Elements

Raise your hand if you’ve tried to get a grid of client logos to center horizontally and vertically inside each logo’s container. It sounds so simple and yet frustratingly it’s not. Sure there are some new CSS properties that can help, but they’re not supported in older versions of Internet Explorer.

Thankfully I stumbled on a solution a few years ago and it still works great today in all major browsers. We’re going to start with the following html:


<article class="clients">
	<span></span><img src="images/img-logo1.png" alt="logo" />
</article>

<article class="clients">
	<span></span><img src="images/img-logo2.png" alt="logo" />
</article>

<article class="clients">
	<span></span><img src="images/img-logo3.png" alt="logo" />
</article>

Yeah I know it’s an empty span. Deal with it. It makes the magic happen for lame browsers. Then jump in with your CSS. You can adjust the width/height, margin and border styling to your heart’s content.


        article.clients {
	float: left;
	display: table-cell;
	vertical-align: middle;
	text-align: center;
	width: 203px;
	height: 150px;
	margin-right: 15px;
	margin-bottom: 15px;
	border: 1px solid #4d4d4d;
	-webkit-border-radius: 3px;
	   -moz-border-radius: 3px;
	             border-radius: 3px;
}

article.clients * {
	vertical-align: middle;
}

article.clients span {
	display: inline-block;
	height: 100%;
	width: 1px;
}

That’s it! You’re all centered up, baby. And if you’re having trouble with the last logo in each row dropping down because of that extra margin on the right just add a class of last to it and target it with some CSS.


<article class="clients last">
	<span></span><img src="images/img-logo1.png" alt="logo" />
</article>

article.clients.last {
	margin-right: 0px;
}

About: Jonathan Longnecker

jonathan longneckerJonathan Longnecker is the co-founder of FortySeven Media– a kick awesome design firm specializing in web design, branding, ExpressionEngine and media creation in Knoxville, TN. He’s also part of the Kick Awesome Show – the show dedicated to design, the web and general nerdery. Find him on twitter (@necker47), and on the web at fortysevenmedia.com.

4 Comments

  1. Adam

    Jonathan, that’s a thing of beauty! I’ve always used javascript to grab the image, make it a background image so that it could be set to 50% 50%, then hide the image element, but this is crazy good!

    Reply
  2. sphil

    what size should the logs be to fit the grid?

    Reply
  3. spud111

    Brilliant, brilliant solution. Easy and clean. Thumb up!

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

More News & Articles

The Essential Guide to Getting Started on Freelance Writing

The Essential Guide to Getting Started on Freelance Writing

Explore the lucrative and fulfilling world of freelance writing with our essential guide. Learn about specialties like blogging, social media, article, and technical writing. Build a portfolio, find work, set up your business, and discover the potential earnings. Embrace the freedom of working from home and follow tips for success in your dream career.

Securing Your Website: A DevOps Security Checklist

Securing Your Website: A DevOps Security Checklist

Learn how to secure your website with a comprehensive DevOps checklist. Dive into SSL/TLS encryption, password practices, and more. Discover the power of Content Security Policy and safeguard your online presence effectively.

EMAIL NEWSLETTER