Designing a dynamic three-column grid layout for showcasing images

I'm in the process of designing a portfolio layout. For large screens, I envision three columns with evenly spaced out images. To better illustrate my idea, you can view an example here:

http://www.example.com/portfolio

I've put together a basic jsfiddle showcasing my concept: http://jsfiddle.net/3h2fm6pb/1/

Below is the HTML structure:

<div id="container">
    <div class="imgContainer">
        <div class="image">
            <img src="http://www.example.com/image1.jpg">
        </div>
        <div class="image">
            <img src="http://www.example.com/image2.jpg">
        </div>
        <div class="image">
            <img src="http://www.example.com/image3.jpg">
        </div>
        <div class="image">
            <img src="http://www.example.com/image4.jpg">
        </div>
        <div class="image">
            <img src="http://www.example.com/image5.jpg">
        </div>
        <div class="image">
            <img src="http://www.example.com/image6.jpg">
        </div>
    </div>
</div>

And here's the SCSS code to style it:

#container {
    max-width: 600px;
    margin: 0 auto;

    .imgContainer{
        width: 100%;
    }

}

.image {
    float: left;
    width: 33%;
    img {
        width: 100%;
        display: block;
    }
}

I'm encountering some trouble achieving consistent white space between the images. Adding padding: 5px; to the .image class leads to only two images fitting per row. Why might this be happening?

I know that the current jsfiddle scales down the entire container when resizing the viewport, but I plan on implementing media queries to adjust the image sizes accordingly for different screen sizes.

Given these factors, what would be the most effective approach to ensure the images have uniform padding between them regardless of viewport size? My previous attempts haven't yielded satisfactory results as the spacing appears uneven upon rearrangement for different viewports.

Here's an outline of how I envision the layout responding to various viewport sizes:

For large screens: Three images are displayed per row with equal gaps between each image and row.

For smaller screens: Two images per row with consistent spacing between them and rows.

For mobile screens: One image per row with uniform padding above and below each image.

I hope this explanation clarifies things. Thank you for your assistance.

Answer №1

To enable the use of padding with width, it is necessary to specify the box-sizing property as border-box. You can refer to this complete example for more details.

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

Issue with font-family not being applied in PHP code

Struggling to preview different fonts? The code below should work, however, the font doesn't seem to change. Check out the output: my Text - Arial.ttf - 1 my Text - Batman.ttf - 1 my Text - Verdana.ttf - 1 While the font is being detected, it& ...

javascript variable pointing to an unknown object

Below is the essential code snippet to consider: JS function ToggleRow(objTwistie, objRow) { if (objRow.style.display == "none") { objRow.style.display = ""; objTwistie.src = "../Images/SectionDown.gif"; } else { objRow.style.display = "n ...

Generate div elements corresponding to individual objects

Previously, I inquired about a similar issue but have not come across any solutions. I made updates to my code, which is now functioning well, however, I am facing a new dilemma. Here is the PHP code I am currently working with: class individual { pu ...

How is it possible for a JavaScript variable sharing the same name as a div Id to automatically pass the div?

This is just ridiculous. Provided HTML <p id = "sampleText"></p> Javascript var sampleText = "Hello World!"; Execution console.log(sampleText); // prints <p id = "sampleText"></p> How is this even possible? I ...

Prevent my buttons from altering their color when hovered over

I have created some visually appealing buttons that I am satisfied with, but when a user clicks on one, the text color changes and the button's hover behavior is altered. I utilized this generator to design the buttons: Below is the CSS code for my b ...

The hover effect is not extending the full width of the dropdown menu

I'm currently working on my first WordPress theme, trying to style the _'s theme. I've been focused on creating a dropdown menu, but I'm facing an issue - if one of the dropdown item headers is too wide, the hover color won't cover ...

Retrieving Information From SVG Files

I have this code snippet saved in a local HTML file: <object id="PriceAdvisorFrame" type="image/svg+xml" data="https://www.kbb.com/Api/3.9.448.0/71071/vehicle/upa/PriceAdvisor/meter.svg?action=Get&amp;intent=buy-used&amp;pricetype=Private Party ...

Adding an HTML tag attribute to a Bootstrap 5 popover using the setAttribute() method: A Step-by

Trying to include HTML tags in a popover setAttribute() function within Bootstrap 5, but the tags are displayed as content rather than being applied as attributes. <button type="button" class="btn btn-secondary mx-2" data-bs-containe ...

What is the best way to showcase the keys of a Python dictionary in an HTML table with the values of each key displayed as a row under its corresponding table header?

I am currently involved in a django project where I perform data analysis using the pandas library and would like to showcase the data (which has been converted into a dictionary) as an HTML table. This is the dictionary I wish to present: my_dict = { ...

Is it possible to access and view the contents of a live website folder using WebMatrix2?

I am looking to make changes to a website using WebMatrix, but the site was originally built with ASP.net. When I try to open the site's folder, I encounter numerous errors. Can anyone advise me on whether it is possible to edit this website despite t ...

showcasing recommended options in the search bar through the use of javaScript

Hey there, I've been working on creating result suggestions for my search bar. The generation process is all set, but I'm facing an issue with displaying the elements on the HTML page. During testing, I keep seeing ${resultItem.name}, and when I ...

Creating a stylish menu with CSS and Bootstrap featuring two beautifully designed rows

Looking to design a header for a webpage that features a logo on the left side in the center, along with two rows of menu items positioned on the right using CSS and Bootstrap classes. Below is an example layout: ---------------------------------------- ...

What is the best way to save comments in a database in order to effectively showcase them as HTML text on a webpage?

I am facing a challenge with a form that allows users to enter multiple lines of text in a text area. Some of the lines may contain HTML markups, such as making one line bold. Now I am unsure about how to properly save this text in my database. Should I s ...

Numerous SVGs sharing identical IDs

Is it possible to include multiple SVGs on an HTML page and utilize the same IDs in each of them? <div> <svg height="0" width="0"> <clipPath id="svgPath"> ........ </svg> <svg height="0" width="0"> < ...

Learn how to dynamically switch the background image of a webpage using a button in AngularJS

Hey there, I'm currently working on incorporating interactive buttons into my website to give users the ability to customize the background. I've been experimenting with Angular to achieve this feature. So far, I've managed to change the ba ...

AngularJS feature enables dynamic file naming, causing JSHint error to appear

One interesting thing about my DOM with AngularJS is the following element... <img class="optional" src="assets/img/{{ctrl.optional}}.png" ng-click="ctrl.clickOptional()"> This image is dynamically generated when the page loads. Whenever I click on ...

How can I fix the issue of the onClick function in my React list not activating the toggle?

How to Activate Toggle Functionality Currently, I am working on a project using React where I developed a list with active states. I have implemented the onClick functions, but unfortunately, they are not working as intended. When I click on the list item ...

Linking to a Different Tab without Tab Mutation with Bootstrap 3.3.5

I am facing a similar issue to the mentioned questions. I am trying to use a link to change tabs, but the problem is that the link only changes the tab content and not the active tab. The most similar question can be found at: Bootstrap linking to a tab w ...

Having trouble transferring my background image from my FTP to my website

I'm having trouble setting a background image for the header on my website. It seems that nothing is loading. The hosting service I use has disabled linking images via external URLs, so I tried uploading the image to Filezilla, but that didn't wo ...

The Label in Material UI TextField is appearing on top of the border,

Incorporating Material UI TextField and Material UI Tab, I have encountered an issue. There are two tabs, each containing a text field. Upon clicking on the TextField, the label's border is supposed to open, but this behavior only occurs if the curren ...