What is the best way to have child divs occupy the entire area of the parent div while also accounting for margins

I am facing a challenge with arranging child divs inside a parent div that has a specific width. Even though I am using isotope to arrange them, the layout modes do not work well for me in terms of spacing.

My goal is to have the child divs fill the space of the parent without any gaps on the far right, while also having margins and padding set for each div. Currently, things are looking decent, as shown here:

Although the margin on the right and top of each div is correct, my aim is to eliminate the margin on the last items of each row. The tricky part is that some divs have varying widths. It should align at the same point as the top-right box, as seen in the image.

The CSS I utilized is as follows:

.global-post{
    padding: 0;
    height: 400px;
    float: none;
    display: inline-block;
    *display: inline;
    zoom: 1;
    vertical-align: top;
    width: 308px;
}

This code sets the width for narrower items, while wider projects have different width values.

Is there anyone who can provide me with guidance on how to resolve this issue?

Answer №1

To create a visually appealing layout, apply a negative left margin to the row, such as margin-left: -20px. Then, include a left margin to each div within that row, like this: margin-left: 20px;

    <div class="row">
      <div class="span">1</div>
      <div class="span">2</div>
      <div class="span">3</div>
      <div class="span">4</div>
    </div>

    <div class="row">
      <div class="span">1</div>
      <div class="span">2</div>
    </div>


    .row{
       margin-left: -20px;
    }

    .span{
       margin-left: 20px;
    }

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

Guide to configuring the initial lookAt/target for a Control

I'm looking to establish the initial 'lookAt' point for my scene, which will serve as both the center of the screen and the rotation control's focus. Ideally, I'd like to set a specific point or object position rather than rotation ...

Switch the Header Image on a Page in WordPress

I am currently using the Sunrise Theme from s5themes.com and I have a question regarding the header image on individual pages. It seems that all pages are displaying the same header image as the homepage, which is not what I want. Attached below is a scre ...

React setState issue experienced only on initial click due to API lag

My goal is to develop a web app using the Poke API to display multiple Pokemon. I have added buttons to allow users to "change the page" and switch the API URL to view the next or previous set of Pokemon. However, I'm facing an issue where the buttons ...

What is the process for using the GitHub API to access a repository's README document?

For my project, I'm utilizing the GitHub API to access the raw README.md file using /repos/{owner}/{repo}/readme. I've successfully executed the call using Thunderclient in VSCode and retrieved the raw file. https://i.sstatic.net/FtkfW.png Howev ...

Develop a JavaScript function to declare variables

I am currently attempting to develop a small memory game where the time is multiplied by the number of moves made by the player. Upon completion of all pairs, a JavaScript function is executed: function finish() { stopCount(); var cnt1 = $("#cou ...

Retrieve JSON Object using a string identifier

I created a script that takes the ID of a link as the name of a JSON dataset. $('.link').click(function() { var dataset = $(this).attr("id"); for (var i = 0; i < chart.series.length; i++) { chart.series[i].setData(lata.dataset ...

Issue with Ext JS: The property 'substring' is being attempted to be read from an undefined value

Hey there! I'm trying to incorporate a grid panel into my view using Extjs 4.1.1, but I keep encountering an error in the browser console that says "Cannot read property 'substring' of undefined". Below is the JavaScript code snippet I am us ...

Unable to fetch the webpage element object

While attempting to extract data from the historical table on investing.com, I encountered an issue where I couldn't retrieve the column item and an error occurred. Traceback (most recent call last): File "<ipython-input-119-ba739f477693>", ...

Delete a designated section from a URL with the power of jQuery

I have a URL like http://myurleg.com/ar/Message.html and I need to change ar to en in it when clicked on. For example, if my current URL is: http://myurleg.com/ar/Message.html After clicking, it should become: http://myurleg.com/en/Message.html I attemp ...

JavaScript error: Trying to access a variable that is not defined results in a ReferenceError

Can I access the variable named val1090 defined in validator.js from runesMetadata.js in nativescript vuejs? This relates to metadata for raddataform in my case. I encountered an error: [Vue warn]: Error in data(): "ReferenceError: val1090 is not defined ...

Why do elements align horizontally in a div even when I specify it to display as a block?

My understanding is that display: block is the default setting. However, even after specifically setting display: block, my div was still aligning items horizontally. The only solution I found was to use: display: flex; flex-direction: column; Any insight ...

Unable to modify the chosen option within a select dropdown

I am trying to change the selected option of a select element using jQuery, but I can't seem to make it work. Here is the code I have: $("#ID option[value=grpValue]").prop('selected', 'selected').change(); If I manually type in a ...

Creating several Doughnut Charts within a single Canvas using Chart.js

Is there a way to display multiple layers of a doughnut chart simultaneously using Chart.js? Currently, I'm only able to see one layer at a time and the others become visible upon hovering over their position... If you have any insights on how to mak ...

Having trouble with nested confirm pop ups?

I am attempting to show an additional confirmation pop-up when the YES button is clicked, but it doesn't seem to be working. Here's my code: $.confirm({ text: "Are you sure you want to delete ?", confirm: function() { $.confirm( ...

Error: An unexpected symbol '<' was encountered after the build process in Vue.js

I just finished deploying a MEVN stack application to heroku. While everything is functioning properly locally, I am encountering a blank page and the following errors in the console post-deployment: Uncaught SyntaxError: Unexpected token '<' ...

Ensure that the method is passed a negative number -1 instead of the literal number 1 from an HTML error

This is an example of my HTML code: <button (mousedown)="onMouseDown($event, -1)"></button> Here is the TypeScript code for handling the mouse down event: onMouseDown(e: MouseEvent, direction: 1|-1) { this.compute.emit(direction); ...

Bookshelfjs fails to return a promise when updating multiple data

I am facing an issue when trying to update multiple rows in my database. The problem lies in the fact that the promise does not return anything, even though the data is successfully saved. Below is a snippet of my code: doUpdate: Promise.method(function ...

Having trouble with the dropdown menu in Bootstrap?

I'm having trouble creating a responsive dropdown menu. When I click on the dropdown items, nothing happens. Here's the code: <div class="navbar-header"> <button type="button" class="navbar-toggel" data-toggel="collapse" data-target="#m ...

Error message: "Root resolution error encountered". Need assistance in granting watchman access?

After setting up a react-native starter project, I was prompted to allow watchman access to my system's files. Unfortunately, I declined and now whenever I try to run the folder, I encounter the following error: Error: unable to resolve root /Users/ck ...

How do you determine the length of an array of arrays using jQuery if it is 'undefined'?

Looking at the array structure below: mdarray = { '0001':{address:'add1',title:'title1'}, '0002':{address:'add2',title:'title2'}, '0003':{address:'add3',title:'titl ...