Grid Test
A Test of CSS Grid and Images
HTML
<h2>Grid Test</h2>
<div id="grid-container">
<div class="">
<img src="http://i.imgur.com/kEmy7gp.jpg" alt="A Rock" />
<p>A beautiful rock structure.</p>
</div>
<div class="">
<img src="http://i.imgur.com/kEmy7gp.jpg" alt="A Rock" />
<p>A beautiful rock structure.</p>
</div>
<div class="">
<img src="http://i.imgur.com/kEmy7gp.jpg" alt="A Rock" />
<p>A beautiful rock structure.</p>
</div>
<div class="">
<img src="http://i.imgur.com/kEmy7gp.jpg" alt="A Rock" />
<p>A beautiful rock structure.</p>
</div>
<div class="">
<img src="http://i.imgur.com/kEmy7gp.jpg" alt="A Rock" />
<p>A beautiful rock structure.</p>
</div>
<div class="">
<img src="http://i.imgur.com/kEmy7gp.jpg" alt="A Rock" />
<p>A beautiful rock structure.</p>
</div>
<div class="">
<img src="http://i.imgur.com/kEmy7gp.jpg" alt="A Rock" />
<p>A beautiful rock structure.</p>
</div>
<div class="">
<img src="http://i.imgur.com/kEmy7gp.jpg" alt="A Rock" />
<p>A beautiful rock structure.</p>
</div>
</div>
SCSS
div#grid-container {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 25px;
width: 95%;
margin: 15px auto;
div {
margin: auto;
overflow: hidden;
// cursor: pointer;
background-color: black;
color: white;
position: relative; /* new */
img {
height: auto;
max-width: 100%;
vertical-align: top; /* new */
}
p {
display: none;
position: absolute; /* changed from `relative` */
padding: 0;
bottom: 40px; /* adjusted */
left: 10px; /* adjusted */
margin: 0;
}
&:hover {
img {
opacity: 0.35;
}
p {
display: block;
}
}
}
}