Skip to content

Instantly share code, notes, and snippets.

@MizR
Created January 30, 2014 15:32
Show Gist options
  • Save MizR/8711079 to your computer and use it in GitHub Desktop.
Save MizR/8711079 to your computer and use it in GitHub Desktop.
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
.cbp-rfgrid {
margin: 35px 0 0 0;
padding: 0;
list-style: none;
position: relative;
width: 100%;
}
.cbp-rfgrid li {
position: relative;
float: left;
overflow: hidden;
width: 25%; /* Fallback */
width: -webkit-calc(100% / 4);
width: calc(100% / 4);
}
.cbp-rfgrid li a,
.cbp-rfgrid li a img {
display: block;
width: 100%;
cursor: pointer;
}
.cbp-rfgrid li a img {
max-width: 100%;
}
/* Flexbox is used for centering the heading */
.cbp-rfgrid li a div {
position: absolute;
left: 20px;
top: 20px;
right: 20px;
bottom: 20px;
background: rgba(71,163,218,0.2);
display: -webkit-flex;
display: -moz-flex;
display: -ms-flex;
display: flex;
-webkit-align-items: center;
-moz-align-items: center;
-ms-align-items: center;
align-items: center;
text-align: center;
opacity: 0;
}
.cbp-rfgrid li a:hover div {
opacity: 1;
}
.cbp-rfgrid li a div h3 {
width: 100%;
color: #fff;
text-transform: uppercase;
font-size: 1.4em;
letter-spacing: 2px;
padding: 0 10px;
}
/* Example for media query: change number of items per row */
@media screen and (max-width: 1190px) {
.cbp-rfgrid li {
width: 20%; /* Fallback */
width: -webkit-calc(100% / 5);
width: calc(100% / 5);
}
}
@media screen and (max-width: 945px) {
.cbp-rfgrid li {
width: 25%; /* Fallback */
width: -webkit-calc(100% / 4);
width: calc(100% / 4);
}
}
@media screen and (max-width: 660px) {
.cbp-rfgrid li {
width: 33.3333333%; /* Fallback */
width: -webkit-calc(100% / 3);
width: calc(100% / 3);
}
}
@media screen and (max-width: 660px) {
.cbp-rfgrid li {
width: 33.3333333%; /* Fallback */
width: -webkit-calc(100% / 3);
width: calc(100% / 3);
}
}
@media screen and (max-width: 400px) {
.cbp-rfgrid li {
width: 50%; /* Fallback */
width: -webkit-calc(100% / 2);
width: calc(100% / 2);
}
}
@media screen and (max-width: 300px) {
.cbp-rfgrid li {
width: 100%;
}
}
<ul class="cbp-rfgrid">
<li><a href="#"><img src="http://lorempixel.com/400/350/nature/1" /><div><h3>Felis catus</h3></div></a></li>
<li><a href="#"><img src="http://lorempixel.com/400/350/nature/2" /><div><h3>Felis catus</h3></div></a></li>
<li><a href="#"><img src="http://lorempixel.com/400/350/nature/3" /><div><h3>Felis catus</h3></div></a></li>
<li><a href="#"><img src="http://lorempixel.com/400/350/nature/9" /><div><h3>Felis catus</h3></div></a></li>
<li><a href="#"><img src="http://lorempixel.com/400/350/nature/5" /><div><h3>Felis catus</h3></div></a></li>
<li><a href="#"><img src="http://lorempixel.com/400/350/nature/6" /><div><h3>Felis catus</h3></div></a></li>
<li><a href="#"><img src="http://lorempixel.com/400/350/nature/7" /><div><h3>Felis catus</h3></div></a></li>
<li><a href="#"><img src="http://lorempixel.com/400/350/nature/8" /><div><h3>Felis catus</h3></div></a></li>
<!-- ... -->
</ul>
// alert('Hello world!');
{"view":"split","fontsize":"80","seethrough":"","prefixfree":"1","page":"all"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment