What causes the odd gaps at the bottom of boxes in a Pure CSS Masonry layout?

Issue with implementing Pure CSS Masonry layout. Using position: relative for the boxes and position: absolute for the content inside each box is causing gaps below each box. Struggling to find a solution, view the code on this codepen: http://codepen.io/kikibres/pen/KWjXeG

Code Snippet:

@import "compass/css3";

*, *:before, *:after {box-sizing:  border-box !important;}

/* Other CSS styles */

body {
 padding:  1em;
 font-family:  "Garamond", serif; 
}

h1 {
  font-size:  3rem;
  font-weight:  800;
}

body {
  line-height:  1.25;
}

p {
 text-align:  left;
}
<h1>Pure CSS Masonry</h1>
<p>By using CSS3 columns, we can easily create a Masonry.js-like layout where random-height blocks fit together.</p>

<div class="servicogallery">


  /* Service Blocks */  

</div>

Desired outcome includes eliminating gaps around the boxes and ensuring content aligns at the bottom of each box. Suspect that the issue lies in the use of position: absolute.

Answer №1

Modify the styling of #services by adding vertical-align: top;

@import "compass/css3";

*, *:before, *:after {box-sizing:  border-box !important;}


.servicogallery {
 -moz-column-gap: 0;
 -webkit-column-gap: 0; 
  -moz-column-count: 3;-webkit-column-count: 3;column-count: 3;
  position: relative;
  display: block;
  width: 100%;
}

#services {
 margin:  0;
 padding:  1rem;
 width:  100%; 
 height: 250px;
 position: relative;
 vertical-align: top;
 display: inline-block;
}
#services span {
    position: absolute;
    bottom: 0;
    left: 0;
    padding: 20px;
    vertical-align: bottom;
}
.a1 {
  background-color: #0026e7;
  color: #FFF;
}
.a2 {
  background-color:/*#189ed8*/#ffffff;
    color: /*#FFF*/#998b75;
}
.a3 {    
  background-color:/*#fff*/#bac0b8;
    color: /*#998b75*/#ffffff;
}
.a4 {    background-color: #646664;
    color: #FFF;
}
.a5 {background-color: #0026e7;
    color: #FFF;
}
.a6 {background-color: #29a1e6;
    color: #FFF;
}
.a7 {background-color: #fff;
    color: #998b75;
}
.a8 {background-color: #bac0b8;
    color: #FFF;
}
.a9 {    background-color: #fff;
    color: #998b75;
}
.a10 {    background-color: #0029e5;
    color: #FFF;
}
.a11 {    background-color: #5e605e;
    color: #FFF;
}

/*  styles for background color, etc; not necessary for this thing to work  */



body {
 padding:  1em;
 font-family:  "Garamond", serif; 
}




h1 {
  font-size:  3rem;
  font-weight:  800;
}

body {
  line-height:  1.25;
}


p {
 text-align:  left;
}
<h1>Pure CSS Masonry</h1>
<p>By using CSS3 columns, we can easily create a Masonry.js-like layout where random-height blocks fit together.</p>

<div class="servicogallery">

  <div id="services" class="a1">
    <span>
      <p>Formulación y Evaluación  de Proyectos de Construcción.</p></span>
  </div>

  <div id="services" class="a2">
    <span>
      <p>Mantenimiento Varios (Edificaciones, Calles, entre otros).</p></span>
  </div>

  <div id="services" class="a3">
    <span>
      <p>Diseño: Arquitectónico, Habitacional, Industrial, Urbano y Comercial.</p></span>
  </div>

  <div id="services" class="a4">
    <span>
      <p>Taludes, Muros.</p></span>
  </div>

  <div id="services" class="a5">
    <span>
      <p>Supervisión de Proyectos</p></span>
  </div>

  <div id="services" class="a6">
    <span>
      <p>Estudios de Factibilidad  Técnica – Económica de proyectos de construcción.</p></span>
  </div>

  <div id="services" class="a7">
    <span>
      <p>Diseño Integral de Obras  de Ingeniería y Arquitectura.</p></span>
  </div>

  <div id="services" class="a8">
    <span>
      <p>Tramitología.</p></span>
  </div>

  <div id="services" class="a9">
    <span>
      <p>Obras de Mitigación</p></span>
  </div>

  <div id="services" class="a10">
    <span>
      <p><strong>Construcción de Obras Civiles  y Remodelaciones:</strong></p>
      <p>Centros comerciales, urbanizaciones, infraestructura: Hidráulica y Víal, complejos industriales, turísticos, deportivo, centros decapacitación, vivienda, centros educativo, hospitales, taludes, muros, obras de mitigación</p>
      <p>Aplicación de pintura con maquinaria industrial avanzada, entre otros.</p></span>
  </div>

  <div id="services" class="a11">
    <span>
      <p>Uso de equipo para la realización de pruebas no destructivas en concreto.</p></span>
  </div>


</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering the error "undefined object" while using the yield keyword in JavaScript

var pi = document.getElementById("pi"); function * calculatePi(){ let q = 1; let r = 0; let t = 1; let k = 1; let n = 3; let l = 3; while (true){ if (4*q+r-t < n*t){ alert(n); yield n; ...

jQuery function failing to produce the intended results

I am trying to apply the active class to the last img element using HTML and jQuery Below is my code in HTML and jQuery: function initialSteps() { $(".row").find("column:last").find("img:first").className += " active"; // this does not work either ...

What are some ways to obscure the stored password in a database with characters like asterisks or other symbols

Currently, I am working on developing the admin features for my website and have been using this resource to assist with adding users: One issue that I have encountered is that when I added a password field, it appears in its stored form which is not idea ...

The compatibility issue between Jquery highlight and show more/less function is causing them to malfunction when used

I am facing an issue where, while trying to search for a specific word to highlight it, the "show more" button closes and only displays the text prior to clicking the button. How can I ensure that the expanded content remains open while searching for a wor ...

What is causing the malfunction of the position within this particular section?

On my website, I have a specific section where I want to showcase four products with arrows on both sides for navigation. However, I am facing an issue with the positioning of the elements. Can someone take a look and help me figure it out? Check out this ...

How to create a scrolling fixed div that moves horizontally and repositions to the center when the page is maximized

I've been searching for a solution to my problem and have managed to figure out the first part, but there's still one issue that I could use some help with. While I have some knowledge of html, css, and basic php, I'm completely new to javas ...

LESS — transforming data URIs with a painting mixin

Trying to create a custom mixin for underlining text, similar to a polyfill for CSS3 text-decoration properties (line, style, color) that are not yet supported by browsers. The idea is to draw the proper line on a canvas, convert it to a data-uri, and the ...

Issue with CSS in Internet Explorer 7

CSS CODE: .search { float: left; width: 100%; display: block; } .search ul.tabs { height: 23px; margin-top: 50px; padding: 0px; } /* FF ONLY */ .search ul.tabs, x:-moz-any-link { height: 26px; margin-top: 50px; padding: 0px; } .search ul.tabs ...

How can you combine accessibility with absolute positioning?

Have you seen our unique hamburger design? https://i.stack.imgur.com/AmT6P.png A simple click will reveal a neat popup (the class "open" is added to a div). https://i.stack.imgur.com/yPydJ.png This cool effect is achieved using fixed positioning, but i ...

Ascending to the Peak within a div

<script type="text/javascript"> $(document).ready(function(){ updateContent(); }); function updateContent(){ $('#mainDiv').load('home.php', function(){ scrollToTop(); }); } ...

"Learn the steps to efficiently input multiple data entries with the same name from a single form into different rows within the same column of

How can I modify this form to insert four separate data entries in the same column upon submission? <form action="entry.php" method="post" > <table> <tr> <td> <input type="text" name="searchid[]" id="searchid" placeh ...

What is the best way to create a gap between two Bootstrap buttons?

I'm attempting to create two buttons in the same line in this code, but it's not working as I want. Take a look below: <div class="w3-show-inline-block"> <div class="w3-bar"> <button class="btn btn-s ...

I am working with a JSON Object in JavaScript and need to retrieve a key using a String variable

Working with a JSON Object in JavaScript can be tricky, especially when trying to access keys stored as Strings using the dot operator. Consider this example of JSON code: "values" : [ { "prop0" : "h", "prop1" : "pizza", "prop2" : "2014- ...

Arrange the <form:radiobuttons> in a vertical position

I'm currently utilizing Spring MVC's <form:radiobuttons> to showcase radio buttons: <form:radiobuttons path="selection" items="${arraySelection}" /> The issue I am facing is that it is displaying the radio buttons in a horizontal la ...

Creating a large and spacious modal in Angular using ngx-bootstrap

I need help with resizing the ngx-modal to cover a large area of the screen. Currently, I am trying to make it so that when something is clicked, the modal should overlay an 80% width grid on a full desktop screen. Despite my attempts at using .modal-xl an ...

Having trouble importing JS into HTML file with NodeJS

I have created a web server using NodeJS that serves the file index.html. However, when I attempt to add a JavaScript file to my HTML document, the browser displays an error message stating The resource "http://localhost:3000/includes/main.js" was blocked ...

How to display text on a new line using HTML and CSS?

How can I properly display formatted text in HTML with a text string from my database? The text should be contained within a <div class="col-xs-12"> and nested inside the div, there should be a <pre> tag. When the text size exceeds the width o ...

"Maximizing the functionality of HTML forms by incorporating PHP for efficient data retrieval

I have been exploring different approaches but I'm struggling to get this to function correctly. As a beginner, I am using form elements with dropdown menus to receive user input and then send the data via email. Here is the HTML and PHP code: <fo ...

iOS devices are not displaying the background image as intended

I've searched through previous answers on the SO platform, but I'm still unable to find a solution that works for me. I have a static Gatsby site with an infinite scrolling background implemented on desktop, and a static image displayed on mobile ...

Sending a form without the need to reload the page

While it's known that Ajax is the preferred method to submit a form without refreshing the page, going through each field and constructing the Post string can be time-consuming. Is there an alternative approach that utilizes the browser's built-i ...