Last active
June 8, 2021 02:59
-
-
Save thinkverse/36c7276c289b962bb83f4c8fc5e369b0 to your computer and use it in GitHub Desktop.
Single-line images gallery with `array_*` functions and `scandir`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:root { | |
--columns: 2; | |
} | |
* { | |
box-sizing: border-box; | |
padding: 0; | |
margin: 0; | |
} | |
body { | |
justify-content: center; | |
padding: 2.5rem 0; | |
display: flex; | |
} | |
main { | |
grid-template-columns: repeat(var(--columns), 1fr); | |
grid-auto-rows: min-content; | |
display: grid; | |
gap: 1.5rem; | |
} | |
img { | |
object-fit: cover; | |
} | |
@media (min-width: 940px) { | |
:root { | |
--columns: 4; | |
} | |
body { | |
justify-content: center; | |
align-items: center; | |
display: flex; | |
height: 100vh; | |
} | |
@media (prefers-reduced-motion: no-preference) { | |
img { | |
transition: all 0.4s ease-in-out; | |
} | |
img:hover { | |
transform: scale(1.1); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Gallery</title> | |
<link rel="stylesheet" href="css/gallery.css"> | |
</head> | |
<body> | |
<main> | |
<?php array_map(fn ($image) => printf('<img src="images/%s" alt="image" width="200" height="200">', $image), array_filter(scandir(realpath(__DIR__ . '/images')), fn ($file) => match (pathinfo($file, PATHINFO_EXTENSION)) { 'jpg', 'jpeg', 'png', 'gif', 'webp' => true, default => false, })); ?> | |
</main> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment