I'm making a list of items, but this has some challenges:
- Responsive;
- Title can have more than one line;
- Sometimes I need to show an icon with a background color instead of the full image.
Here is an image of the expected end result:
Andhere,whatI'vealreadyachieved:
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.items {
margin: 50px auto 0;
width: 90%;
}
.items::after {
clear: both;
content: "";
display: table;
}
.items .item {
border: 1px solid #ddd;
float: left;
width: 32%;
}
.items .item:nth-child(3n+2) {
margin: 0 2%;
}
.items .item .image {
background: #eee;
}
.items .item .image img {
display: block;
width: 100%;
}
.items .item .image img.icon {
height: 80%;
margin: 0 auto;
position: relative;
top: 10%;
width: auto;
}
.items .item .title {
margin: 0;
padding: 20px;
}
<div class="items">
<a href="#" class="item">
<div class="image">
<img src="http://placehold.it/200x100"></div><h4class="title">Hi. I'm a title.</h4>
</a>
<a href="#" class="item">
<div class="image">
<img src="http://placehold.it/80x80"class="icon">
</div>
<h4 class="title">Hi. I'm a title.</h4>
</a>
<a href="#" class="item">
<div class="image">
<img src="http://placehold.it/200x100"></div><h4class="title">Hi. I'm a title.</h4>
</a>
</div>