6
I’m making a list of items, but this has some challenges:
- Responsive;
- Title may have more than one line;
- Sometimes I need to show an icon with a background color instead of the full image.
Here is a picture of the expected end result:
And here, what I’ve already achieved:
* {
-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>
<h4 class="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>
<h4 class="title">Hi. I'm a title.</h4>
</a>
</div>
Codepen: http://codepen.io/caio/pen/ygkfm/
As you can see, I couldn’t set the same scale for the div
image when it has an icon. Is there any solution to my problem?
Do you want to do this without using @media-query? I think working with percentage for responsive in some cases is better and easy to get the result using specific css for each resolution.
– Mattos
Hi @Mattos, in my case it needs to be in percentage, but I agree with your point.
– Caio Tarifa
Caio, has some questions of yours in which no response was accepted. If none solved your problem, it is perfectly normal to leave it open, but if any of them have been solved in the answers, you can accept to complete the post. Remembering that, if solved otherwise, you can post your solution as answer to your own question and accept it, helping future visitors.
– Bacco