A common way to lay out a list of visual things is a grid like above.
This one may be difficult. Especially since you have to use this markup:
<ul class="images">
<li>
<figure>
<a href="#">
<img src="https://placebear.com/300/200">
<figcaption>Be Aware of the Bear</figcaption>
</a>
</figure>
</li>
<li>
<figure>
<a href="#">
<img src="https://placebear.com/300/201">
<figcaption>Smokey</figcaption>
</a>
</figure>
</li>
<li>
<figure>
<a href="#">
<img src="https://placebear.com/300/202">
<figcaption>Gone Fishin</figcaption>
</a>
</figure>
</li>
<li>
<figure>
<a href="#">
<img src="https://placebear.com/301/203">
<figcaption>I'm stuck</figcaption>
</a>
</figure>
</li>
<li>
<figure>
<a href="#">
<img src="https://placebear.com/305/205">
<figcaption>PDA?</figcaption>
</a>
</figure>
</li>
<li>
<figure>
<a href="#">
<img src="https://placebear.com/301/202">
<figcaption>Hello?</figcaption>
</a>
</figure>
</li>
</ul>
img
is an inline element, and will get a mysterious space around it
when when margin is set to zero. This is because inline elements get space around them
from the line-height
. You'll want to set your .figure img
to display: block
so it fills
the space and doesn't have weird layout effects.float: left
. But I want to use 1% of that space for margin on each item.margin-left
only. Now you don't have to worry about the items at the end of the line - they'll set neatly against the edge..images li:nth-child(3n+1)
to clear: left
and margin-left: 0
.nth-child
is a psuedoclass that can select even, odd, third, etc, of the matching elements. This is useful for striping tables, or clearing the margin of every third+1 element. Read about it on MDN.n
is 0
, 3n+1 is 1, or the first element.figcaption
is on top of the image. Perhaps position: absolute
is a useful tool for this.figcaption
is also transparent. You can do that with rgba
colors. If you've never seen this before, you should look it up on MDN).The images are from placebear.com. It's exactly what it sounds like it is. There's also placekitten.com, if you want to make "I can haz placeholder art" jokes.
Right now, if there were a 7th image, it would hang on the left. What if you wanted it centered?
Perhaps, rather than floating, you could make a layout like this where the li
's are
inline-block
s, and set text-align:center;
on the parent, so if there's 3 the fill the row,
but if there's 1 or 2 they're centered across the row.
I bet that would work 😉