Creating a grid layout similar to Tumblr using HTML and CSS

Struggling all day to figure out how to create a Tumblr-style grid for my website, I'm reaching out here for some assistance. Here is the page: I have a grid of images on my project page that initially looked fine, but as I try to add new elements, it's starting to look messy. Take a look at this screenshot. I've attempted various solutions, but there always seems to be a white gap present (even when it shouldn't be). For reference, here's an example of what I am aiming for:

Here is the HTML code (including filter):

<div id="myBtnContainer">
  <button class="btn active" onclick="filterSelection('all')"> ALL</button>
  <button class="btn" onclick="filterSelection('imprime')"> PRINTED</button>
  <button class="btn" onclick="filterSelection('digital')"> DIGITAL</button>
  <button class="btn" onclick="filterSelection('picture')"> PHOTO</button>
</div>
<div class="pic"> <a href="ego_graphique.html"><img class="filterDiv picture" src="images/ego5-4.jpg" alt="graphic ego" style="width:40% "> </a> <a href="institut_poincare.html"><img class="filterDiv imprime" src="images/ihp1_1.jpg" alt="posters for henri poincaré institute" style="width:25%"> </a> <a href="jpo_gat_17.html"><img class="filterDiv imprime" src="images/jpogat17.png" alt="open house gué à tresmes high school 2017" style="width:25%"></a><a href="details_et_des_tailles.html"><img class="filterDiv imprime" src="images/detailbook1.jpg" style="width:35%"></a> <a href="experience_de_la_duree.html"><img class="expav filterDiv digital" src="images/expavstatic.png" alt="time experience" style="width:35%" ></a></div>

And the CSS:

html {
    position: relative;
    min-height: 100%;
}

body {
background: white;
font-size: 20px;
font-family: Helvetica, Arial, sans-serif;
line-height: 25px;
margin: 0 0 900px; /* bottom = footer height */
padding: 25px;
}

    .img{
    margin: 20px;
}

/* FILTER */    
.container {
    overflow: hidden;
}

.filterDiv {
    float:left;
    width: 100px;
    line-height: 100px;
    text-align: center;
    margin: 13px;
    display:none; 
}

.show {
    display: block;

}
.pic
{
      max-width: 100%;
}

I’m still learning HTML and CSS, so I acknowledge that my code may not be perfect or optimized yet. Please excuse any language errors, English is not my native tongue.

Thank you for your assistance!

EDIT @ben_fluleck

Thanks for your reply. The "height: 100%" causes distortion in the aspect ratio of my images. When I use "max-width" and "max-height" instead of "height" and "width", the white gap reappears. Additionally, I need to maintain the "display: none" on filterDiv for the filtering functionality (which involves JavaScript). Currently, the filtering works, but the images are not showing correctly (before:image, after:image). Filtered elements seem to leave a white space instead of disappearing. I tried adapting some Tumblr HTML without success. Simple tasks prove challenging... I really need a solution that automatically adjusts sizing like a Tumblr theme, as adding new content will likely lead to further disarray. I understand the footer implementation needs improvement; I managed to create it based on available resources, but it's still not ideal. Thank you again for your help! Let’s address the footer later; right now, resolving the grid issue is my priority.

Answer №1

Apologies for the mistake in my CSS code above, where I referred to the picture as "pic" instead of "pics". You can easily control the size of the images by adding a width property to them in the CSS. It's best to avoid inline styling for width and use percentages in the CSS for more flexibility.

I've created a fiddle that you can work on further to get a better understanding of the layout:

.container {
  display: flex;
  justify-content: center;
  align-items: center;
}

.box {
  flex: 1 1 auto;
  color: white;
  font-size: 50px;
  text-align: center;
  padding: 10px;
}

/* Colors for each box */

.box1 {
  background: #1abc9c;
}

.box2 {
  background: #3498db;
}

.box3 {
  background: #9b59b6;
}

Check out the updated fiddle here

Answer №2

Check out these CSS Layouts that can help organize your images effectively

Flexbox or Grid

Specify a viewport height in the body and base your design on that

body{
background: white;
font-size: 20px;
font-family: Helvetica, Arial, sans-serif;
line-height: 25px;
/* margin: 0 0 900px; */
padding: 25px;
height: 100vh;
display: flex;
flex-direction: column;
}

.pic {
display: grid;
grid-template-columns: repeat(4,1fr);
grid-gap: 10px;
}

.filterDiv {
float: left;
width: 100%;
line-height: 100px;
text-align: center;
height: 100%; /*optional if you want them to be all the same same */
}

.show {
/* display: block; */
}

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

Is there a way to determine programmatically if a GIF image is animated?

Check out this link to another question I posted about the same project I'm currently working on. Having some background information might be useful for you. In summary, I've downloaded a large number of images from 4scrape and now I need to sor ...

.htacces Disables Styling on Page

I've been trying to understand the functionality of .htaccess RewriteRule. Here is a URL example where I have experimented with .htaccess: http://example.com/test/home This used to be: http://example.com/test/index.php?p=1 My goal is to redirect ...

The Div elements are not displaying properly in the correct size on the responsive webpage

Looking to create a responsive design for a follow page. Although I've managed to make it work, adding a line at the top of each row is causing layout issues and the Box container is not displaying consistently in size. I attempted to set up a fiddl ...

Learn how to configure an Angular2 Template Driven form element by implementing two-way binding and integrating template driven form validation techniques

Can anyone help me figure out the correct way to set up an Angular template driven form element for both validation and two-way binding? I've tried using ngModel in different ways, but cannot seem to achieve two-way binding without encountering issues ...

Exploring the world of jQuery animation and background colors with Animate()

I'm currently attempting to implement a basic pulse effect by utilizing JQuery to modify the background color. However, I am facing issues with animating the backgroundColor property. function show_user(dnid) { /* dnid represents the HTML ID of a ...

Examining the scroll-down feature button

I'm currently experimenting with a scroll down button on my website and I'm perplexed as to why it's not functioning properly. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" c ...

URL relative references across multiple domains

Here's a quick question: When developing themes and coding, how do you navigate linking to different files in your html/css code? For example: At our company, we mostly use <base target="http://whatever"> in our main template and then simply r ...

Position text input boxes on the right side of the div element

I am seeking help with aligning the text inputs to the edge of .formColumn2 so they appear in a neat line together. I have attempted using margin-right:0 and margin-left, but these solutions end up extending the .formColumn2 div which is not my desired out ...

How to Make Bootstrap 3 Collapse Panels Stand Out with an Active Class

First of all, here is the fiddle link: http://jsfiddle.net/krish7878/h38jn324 I have a simple question. When a panel is clicked and it expands to show its contents, a class 'active' should be added to 'panel-heading'. I came across a ...

The functionality of HTML5 canvas image objects is not functioning as expected

I have been working on a function to retrieve an image object using HTML5 canvas, but I keep encountering an error alert (onerror event) function FetchImage() { var img = new Image(); img.src = "http://localhost/assets/images/loadedsprite.png"; ...

problems with hovering over radio buttons in Internet Explorer 9

Encountering a curious issue in IE9: When hovering over my top level wrapper div, the first radio button seems to be triggered as though it's being hovered over. This means that even if the last radio input is selected, clicking anywhere within the wr ...

Unable to locate the sibling element using CSS Selector with Selenium

When using a CSS Selector to click on the next sibling element in Selenium WebDriver, an InvalidSelectorException is thrown. If we consider my DOM structure: <div class="checkbox-group"> <div> <span class="checkbox">::aft ...

When scrolling, the selected text does not maintain its correct position

I'm looking to enable my users to search by selecting text. Once they select text, a new button will appear on the right side of the selected text giving them the option to search or not. However, when the user scrolls to the bottom of the page, the p ...

Utilize React Native to showcase JSON data in a visually appealing way by organizing it into titles and corresponding lists for both

I created a live code on Expo.io to showcase JSON data categories as titles and the subs as a list. This code utilizes .map() to retrieve data from an array. import React, { useState } from 'react'; import { Text, View, StyleSheet, Button, FlatLi ...

Creating a Conditional Structure in HTML: A Step-by-Step Guide

My website is in need of a form that can identify the user's role based on their name input. This feature is essential for individuals with private roles. Is it possible to achieve this using HTML alone, without relying on JavaScript? If not, what st ...

React Native - Scaling images dynamically

I have a responsive photo grid built within a mobile app. I want to display three images across the screen with equal spacing between them. All the images are squares. Unfortunately, using percentages for each image's width and height is not possible ...

Encountered a problem while trying to update a list item in Vue.js

Greetings Everyone, I've successfully implemented a basic CRUD functionality in VueJS. The values are being inserted into a list, from which I can read and delete them. However, I'm facing an issue with updating any value. When I try to ...

switch between showing and hiding dynamic table rows

As I dynamically add rows to a table, each row can either be a parent row or a child row. My goal is to toggle the visibility of child rows when the parent row is clicked. if (response != null && response != "") { ...

Padding on hover for navigation bar dropdowns

Having issues with a drop-down navigation menu that works fine except for the "videos" item. The hover color change doesn't cover the entire width due to padding settings. Struggling to fix this without affecting the "photography" item. Need help figu ...

How do I go about transferring a file using PHP?

I'm working on file uploads and saving them in a directory. However, I'm facing an issue: when a file is denied it needs to be deleted from the directory. This part is sorted out. But what if the file is approved? Should I use rename() or move_up ...