Hey everyone,
So I am having some difficulty understanding why when I create a demo page for a masonry photo gallery displays perfectly, yet when I use the same code for the file it needs to go in, there’s spacing all around the images and makes it look like crap.
Here is the HTML code for the page where everything is displaying correctly:
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="css/bootstrap.css" media="screen" title="no title" charset="utf-8">
<link rel="stylesheet" href="css/style.css" media="screen" title="no title" charset="utf-8">
</head>
<body>
<h1>Masonry Gallery</h1>
<section id="photos">
<img src='http://placekitten.com/300/276' alt=''>
<img src='http://placekitten.com/300/333' alt=''>
<img src='http://placekitten.com/300/358' alt=''>
<img src='http://placekitten.com/300/261' alt=''>
<img src='http://placekitten.com/300/299' alt=''>
<img src='http://placekitten.com/300/359' alt=''>
<img src='http://placekitten.com/300/309' alt=''>
<img src='http://placekitten.com/300/252' alt=''>
<img src='http://placekitten.com/300/371' alt=''>
<img src='http://placekitten.com/300/303' alt=''>
<img src='http://placekitten.com/300/399' alt=''>
<img src='http://placekitten.com/300/229' alt=''>
<img src='http://placekitten.com/300/322' alt=''>
<img src='http://placekitten.com/300/365' alt=''>
<img src='http://placekitten.com/300/345' alt=''>
<img src='http://placekitten.com/300/342' alt=''>
<img src='http://placekitten.com/300/283' alt=''>
<img src='http://placekitten.com/300/319' alt=''>
<img src='http://placekitten.com/300/398' alt=''>
<img src='http://placekitten.com/300/227' alt=''>
<img src='http://placekitten.com/300/235' alt=''>
<img src='http://placekitten.com/300/318' alt=''>
<img src='http://placekitten.com/300/297' alt=''>
<img src='http://placekitten.com/300/230' alt=''>
<img src='http://placekitten.com/300/261' alt=''>
<img src='http://placekitten.com/300/304' alt=''>
<img src='http://placekitten.com/300/365' alt=''>
<img src='http://placekitten.com/300/294' alt=''>
<img src='http://placekitten.com/300/331' alt=''>
<img src='http://placekitten.com/300/208' alt=''>
</section>
</body>
</html>
Here is the CSS that ties along with this page (that works correctly)
* { margin: 0; padding: 0; }
#photos {
/* Prevent vertical gaps */
line-height: 0;
-webkit-column-count: 5;
-webkit-column-gap: 0px;
-moz-column-count: 5;
-moz-column-gap: 0px;
column-count: 5;
column-gap: 0px;
}
#photos img {
/* Just in case there are inline attributes */
width: 100% !important;
height: auto !important;
}
@media (max-width: 1200px) {
#photos {
-moz-column-count: 4;
-webkit-column-count: 4;
column-count: 4;
}
}
@media (max-width: 1000px) {
#photos {
-moz-column-count: 3;
-webkit-column-count: 3;
column-count: 3;
}
}
@media (max-width: 800px) {
#photos {
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
}
}
@media (max-width: 400px) {
#photos {
-moz-column-count: 1;
-webkit-column-count: 1;
column-count: 1;
}
}
and here is the file I’m trying to use this code with (HTML):
<?php require_once(__DIR__."/../includes/config.php"); ?>
<?php require_once(__DIR__."/../includes/functions.php"); ?>
<?php require_once(__DIR__."/includes/header.php"); ?>
<?php
try {
$pdo = DB::getConnection();
$sql = 'SELECT * FROM pages WHERE id = 1';
$q = $pdo->query($sql);
$q->setFetchMode(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
die("Could not connect to the database $dbname :" . $e->getMessage());
}
?>
<div id="main">
<div class="pages">
<?php while ($row = $q->fetch()): ?>
<h1><?php echo $row['title'];?></h1>
<p><?php echo $row['body']; ?></p>
<?php endwhile; ?>
<!-- masonry gallery goes here -->
<div id="photos">
<img src='http://placekitten.com/300/276' alt=''>
<img src='http://placekitten.com/300/333' alt=''>
<img src='http://placekitten.com/300/358' alt=''>
<img src='http://placekitten.com/300/261' alt=''>
<img src='http://placekitten.com/300/299' alt=''>
<img src='http://placekitten.com/300/359' alt=''>
<img src='http://placekitten.com/300/309' alt=''>
<img src='http://placekitten.com/300/252' alt=''>
<img src='http://placekitten.com/300/371' alt=''>
<img src='http://placekitten.com/300/303' alt=''>
<img src='http://placekitten.com/300/399' alt=''>
<img src='http://placekitten.com/300/229' alt=''>
<img src='http://placekitten.com/300/322' alt=''>
<img src='http://placekitten.com/300/365' alt=''>
<img src='http://placekitten.com/300/345' alt=''>
<img src='http://placekitten.com/300/342' alt=''>
<img src='http://placekitten.com/300/283' alt=''>
<img src='http://placekitten.com/300/319' alt=''>
<img src='http://placekitten.com/300/398' alt=''>
<img src='http://placekitten.com/300/227' alt=''>
<img src='http://placekitten.com/300/235' alt=''>
<img src='http://placekitten.com/300/318' alt=''>
<img src='http://placekitten.com/300/297' alt=''>
<img src='http://placekitten.com/300/230' alt=''>
<img src='http://placekitten.com/300/261' alt=''>
<img src='http://placekitten.com/300/304' alt=''>
<img src='http://placekitten.com/300/365' alt=''>
<img src='http://placekitten.com/300/294' alt=''>
<img src='http://placekitten.com/300/331' alt=''>
<img src='http://placekitten.com/300/208' alt=''>
</div>
</div>
</div>
<?php require_once(__DIR__."/includes/footer.php"); ?>
and here is the CSS to go along with the (not working) HTML file:
* {
box-sizing: border-box;
}
/* force scrollbar */
html {
overflow-y: scroll;
}
body{
background-color: #f8f8f8;
}
/* top/slide down nav section */
.overlay {
height: 0%;
width: 100%;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-y: hidden;
transition: 0.5s;
}
.overlay-content {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}
.overlay li a {
padding: 8px;
text-decoration: none;
font-size: 36px;
color: #818181;
display: block;
transition: 0.3s;
}
.overlay li a:hover, .overlay a:focus {
color: #f1f1f1;
}
.overlay .closebtn {
position: absolute;
top: 20px;
right: 45px;
font-size: 60px;
}
/* Masonry gallery */
* { margin: 0; padding: 0; }
#photos {
/* Prevent vertical gaps */
line-height: 0;
-webkit-column-count: 5;
-webkit-column-gap: 0px;
-moz-column-count: 5;
-moz-column-gap: 0px;
column-count: 5;
column-gap: 0px;
margin: 0;
padding: 0;
}
#photos img {
/* Just in case there are inline attributes */
width: 100% !important;
height: auto !important;
}
@media (max-width: 1200px) {
#photos {
-moz-column-count: 4;
-webkit-column-count: 4;
column-count: 4;
}
}
@media (max-width: 1000px) {
#photos {
-moz-column-count: 3;
-webkit-column-count: 3;
column-count: 3;
}
}
@media (max-width: 800px) {
#photos {
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
}
}
@media (max-width: 400px) {
#photos {
-moz-column-count: 1;
-webkit-column-count: 1;
column-count: 1;
}
}
The image above where there are no gaps around the images is what I want to accomplish. Any help or advice would be greatly appreciated. I’m sort of new to masonry stuff. Thanks!