Image gallery made with Flexbox and CSS Grid.
A Pen by Katherine Kato on CodePen.
Image gallery made with Flexbox and CSS Grid.
A Pen by Katherine Kato on CodePen.
<nav> | |
<div class="container"> | |
<div class="grid"> | |
<div class="column-xs-12 column-md-10"> | |
<p id="highlight">Katherine Kato</p> | |
</div> | |
<div class="column-xs-12 column-md-2"> | |
<ul> | |
<li><a href="#" class="active">Work</a></li> | |
<li><a href="#">About</a></li> | |
</ul> | |
</div> | |
</div> | |
</div> | |
</nav> | |
<section class="gallery"> | |
<div class="container"> | |
<div class="grid"> | |
<div class="column-xs-12 column-md-4"> | |
<figure class="img-container"> | |
<img src="https://source.unsplash.com/8b1cWDyvT7Y" /> | |
<figcaption class="img-content"> | |
<h2 class="title">Smart Watch</h2> | |
<h3 class="category">Showcase</h3> | |
</figcaption> | |
<span class="img-content-hover"> | |
<h2 class="title">Smart Watch</h2> | |
<h3 class="category">Showcase</h3> | |
</span> | |
</figure> | |
</div> | |
<div class="column-xs-12 column-md-4"> | |
<figure class="img-container"> | |
<img src="https://source.unsplash.com/5VXH4RG88gc" /> | |
<figcaption class="img-content"> | |
<h2 class="title">Camera Film</h2> | |
<h3 class="category">Showcase</h3> | |
</figcaption> | |
<span class="img-content-hover"> | |
<h2 class="title">Camera Film</h2> | |
<h3 class="category">Showcase</h3> | |
</span> | |
</figure> | |
</div> | |
<div class="column-xs-12 column-md-4"> | |
<figure class="img-container"> | |
<img src="https://source.unsplash.com/XtUd5SiX464"> | |
<figcaption class="img-content"> | |
<h2 class="title">Coffee</h2> | |
<h3 class="category">Showcase</h3> | |
</figcaption> | |
<span class="img-content-hover"> | |
<h2 class="title">Coffee</h2> | |
<h3 class="category">Showcase</h3> | |
</span> | |
</figure> | |
</div> | |
<div class="column-xs-12 column-md-6"> | |
<figure class="img-container"> | |
<img src="https://source.unsplash.com/JYGnB9gTCls" /> | |
<figcaption class="img-content"> | |
<h2 class="title">Phone</h2> | |
<h3 class="category">Showcase</h3> | |
</figcaption> | |
<span class="img-content-hover"> | |
<h2 class="title">Phone</h2> | |
<h3 class="category">Showcase</h3> | |
</span> | |
</figure> | |
</div> | |
<div class="column-xs-12 column-md-6"> | |
<figure class="img-container"> | |
<img src="https://source.unsplash.com/-RBuQ2PK_L8" /> | |
<figcaption class="img-content"> | |
<h2 class="title">Keyboard</h2> | |
<h3 class="category">Showcase</h3> | |
</figcaption> | |
<span class="img-content-hover"> | |
<h2 class="title">Keyboard</h2> | |
<h3 class="category">Showcase</h3> | |
</span> | |
</figure> | |
</div> | |
<div class="column-xs-12"> | |
<figure class="img-container"> | |
<img src="https://source.unsplash.com/P44RIGl9V54" /> | |
<figcaption class="img-content"> | |
<h2 class="title">Wrist Watch</h2> | |
<h3 class="category">Showcase</h3> | |
</figcaption> | |
<span class="img-content-hover"> | |
<h2 class="title">Wrist Watch</h2> | |
<h3 class="category">Showcase</h3> | |
</span> | |
</figure> | |
</div> | |
</div> | |
</div> | |
</section> | |
<footer> | |
<div class="container"> | |
<div class="grid"> | |
<div class="column-xs-12"> | |
<ul class="social"> | |
<li><a href="https://twitter.com/kato_katherine" target="_blank" rel="noopener noreferrer"><span class="fab fa-twitter"></span></a></li> | |
<li><a href="https://codepen.io/kathykato" target="_blank" rel="noopener noreferrer"><span class="fab fa-codepen"></span></a></li> | |
<li><a href="https://github.com/kathykato" target="_blank" rel="noopener noreferrer"><span class="fab fa-github"></span></a></li> | |
</ul> | |
<p class="copyright">© Copyright 2018 Katherine Kato</p> | |
</div> | |
</div> | |
</div> | |
</footer> |
const imgContent = document.querySelectorAll('.img-content-hover'); | |
function showImgContent(e) { | |
for(var i = 0; i < imgContent.length; i++) { | |
imgContent[i].style.left = e.pageX + 'px'; | |
imgContent[i].style.top = e.pageY + 'px'; | |
} | |
}; | |
document.addEventListener('mousemove', showImgContent); |
@import url('https://fonts.googleapis.com/css?family=Barlow:400,500,700'); | |
$white: #fff; | |
$black: #2e2e2e; | |
$gray: #787878; | |
$highlight: #ea8478; | |
$footer: #f7f7f7; | |
* { | |
-webkit-box-sizing: border-box; | |
box-sizing: border-box; | |
&::before, &::after { | |
-webkit-box-sizing: border-box; | |
box-sizing: border-box; | |
} | |
} | |
body { | |
font-family: 'Barlow', sans-serif; | |
font-size: 1.125rem; | |
line-height: 1.5; | |
color: $gray; | |
background: $white; | |
text-rendering: optimizeLegibility; | |
} | |
ul li { | |
margin: 0 1.5rem 0 0; | |
} | |
a { | |
color: $gray; | |
text-decoration: none; | |
-webkit-transition: all 0.2s ease; | |
-o-transition: all 0.2s ease; | |
transition: all 0.2s ease; | |
&:hover { | |
color: $black; | |
} | |
&.active { | |
color: $black; | |
} | |
} | |
nav { | |
padding: 2.5rem 0 2.5rem 0; | |
ul { | |
display: -webkit-box; | |
display: -ms-flexbox; | |
display: flex; | |
-webkit-box-pack: left; | |
-ms-flex-pack: left; | |
justify-content: left; | |
} | |
li { | |
font-size: 1.25rem; | |
&:nth-child(2) { | |
margin: 0; | |
} | |
} | |
} | |
#highlight { | |
color: $highlight; | |
font-size: 1.25rem; | |
} | |
.gallery { | |
padding: 0 0 4rem 0; | |
} | |
.img-container { | |
width: 100%; | |
height: 500px; | |
cursor: pointer; | |
overflow: hidden; | |
&:hover .img-content-hover { | |
display: block; | |
} | |
} | |
img { | |
width: 100%; | |
height: 500px; | |
-o-object-fit: cover; | |
object-fit: cover; | |
-webkit-transform: scale(1); | |
-ms-transform: scale(1); | |
transform: scale(1); | |
-webkit-transition: all 0.3s ease-in-out; | |
-o-transition: all 0.3s ease-in-out; | |
transition: all 0.3s ease-in-out; | |
&:hover { | |
-webkit-transform: scale(1.05); | |
-ms-transform: scale(1.05); | |
transform: scale(1.05); | |
} | |
} | |
.img-content-hover { | |
position: absolute; | |
z-index: 1; | |
white-space: nowrap; | |
display: none; | |
padding: 1rem; | |
background: $white; | |
font-weight: 400; | |
margin-top: 1.25rem; | |
margin-left: -2rem; | |
} | |
.title { | |
color: $black; | |
font-size: 1.5rem; | |
font-weight: 700; | |
} | |
.category { | |
font-size: 1rem; | |
color: $gray; | |
} | |
.img-content { | |
display: none; | |
} | |
.social, .copyright { | |
margin: 1rem; | |
} | |
.social li { | |
display: inline-block; | |
} | |
footer { | |
padding: 1rem 0; | |
background: $footer; | |
text-align: center; | |
} | |
@supports (display: grid) { | |
.gallery .grid { | |
grid-gap: 1rem; | |
} | |
} | |
@media(min-width: $md) { | |
nav ul { | |
-webkit-box-pack: right; | |
-ms-flex-pack: right; | |
justify-content: right; | |
} | |
} | |
@media screen and (max-width: 1024px) { | |
img:hover { | |
-webkit-transform: none; | |
-ms-transform: none; | |
transform: none; | |
} | |
.img-container { | |
height: 100%; | |
&:hover .img-content-hover { | |
display: none; | |
} | |
} | |
.img-content { | |
display: block; | |
padding: 1rem 0; | |
} | |
} |
<link href="https://codepen.io/kathykato/pen/57f0b5b76e6aa7e4917e08b81d378d7b" rel="stylesheet" /> | |
<link href="https://use.fontawesome.com/releases/v5.0.12/css/all.css" rel="stylesheet" /> |