Images are all different sizes. I’m using some jquery to resize them proportionally at 170px to fit inside the 180px #co-logo div. How can I get them to line up in the center of that #co-logo? I can’t find a solution that works.
#co-logo
{
float: left;
width: 180px;
height: 180px;
margin: 20px 0 20px 20px;
background-color: White;
border: 1px solid #d6d5d5;
text-align: center;
position: relative;
}
#co-logo img
{
position: absolute;
top: 50%;
left: 50%;
}

As you can see in your example, the images are positioned at the center (starting from the top left corner).
To make the center the way you desire, I suggest this solution:
How to make an image center (vertically & horizontally) inside a bigger div
Since you’re already using jQuery to manipulate the image’s size, add their
margin-topandmargin-leftprogrammatically (half for each).EDIT:
(I don’t know how you’re placing the image size, you may need to change the
height()andwidth()by$("#co-logo img").css('height')and$("#co-logo img").css('width'))The javascript with jQuery to add the inline styles:
simplified:
explained:
EDIT 2:
Using
eachto loop between every image.Assuming you had the same ID for each block, you need to swap it with a class, like
.co-logoinstead of#co-logo(because IDs are unique), call the each like this:That will do the trick!