The integration of jQuery Masonry with margin-right for a seamless and

I have a row with two columns, where the first column has a right margin and the second one does not. I would like to use jQuery Masonry to eliminate any empty spaces. However, it seems that the margin right does not interact well with Masonry.

Is there a way to maintain the same width for all boxes and remove the margin after the second box in the row?

Below is the HTML code:

<div class="list">

    <div class="item"></div>
    <div class="item no-margin"></div>

    <div class="item"></div>
    <div class="item no-margin"></div>

    <div class="item"></div>
    <div class="item no-margin"></div>
</div>

CSS:

.list{
    width: 350px;
    border: 1px solid red;
    overflow: hidden;
}

.item{
    width: 150px;
    height: 150px;
    background: green;
    margin-right: 50px;  
    margin-bottom: 50px;
    float: left;
}

.no-margin{
    margin-right: 0 !important;

}

jQuery:

jQuery('.list').masonry({
        itemSelector: '.item',
});

Demo: http://jsfiddle.net/Y7USd/

Answer №1

If you're using jQuery Masonry, don't forget about the gutterWidth option which allows you to add extra margin or gutter between elements.

One important thing you may have overlooked in your fiddle is including modernizr-transitions.js.

For a functioning demonstration, check out this example: http://jsfiddle.net/codemonkey/8hG2s/

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

Searching for the active tab with jquery: A step-by-step guide

Trying to implement tabs using jQuery without relying on jQuery UI. How can I determine which tab was clicked? Here is the structure of my tabs: <div class="tabs"> <!-- Tab section begins --> <div class="tabview-content"> ...

Convert your website to AJAX with Internet Explorer versions 8 and 9 using the URL /#./profile

While Ajaxify performs well in modern browsers, I have encountered some strange URL behavior when using IE8 and 9. The URL ends up looking like http://domain.com/#./profile instead of http://domain.com/profile Is this a known issue or am I missing somethi ...

Steps for resolving the "endless redirection loop" issue in Sharepoint

I am currently learning Javascript and working on setting up a multi-language Sharepoint site. I am trying to implement a code into each page that checks the user's email and the language in the URL (Portuguese or Spanish) and then redirects according ...

How to toggle the visibility of an element in an array using AngularJS and JavaScript

Is there a way to show additional information when an item in ng-repeat is clicked, and then hide this extra info when the mouse leaves that same item? One issue I am facing with the code snippet below is that when a user clicks on a different item, it al ...

Footer content no longer overlapping

I'm currently utilizing Bootstrap and attempting to create a footer that stays at the bottom of the page. The issue arises when there is an excess of content, causing the footer to overlap with the content. My layout structure looks like this: <bo ...

Issues with displaying video content and controlling the Bootstrap 5 video carousel

I have encountered an issue while coding a website for a friend's company. He requested a video carousel to be added to his existing site, so I incorporated links and scripts for Bootstrap in order to create a gallery for his products and a carousel t ...

Using jQuery to find a specific element within a variable in an HTML template in order to dynamically load available choices

The issue at hand is this: I am attempting to utilize a dynamic jQuery modal form that changes the content of a table based on a template loaded within it. The template includes a select element that I intend to populate with data as soon as it is inserted ...

Switch the execution of the script by clicking on the button

My website has a script that hides the navigation when scrolling down and shows it again when scrolling up slightly. However, I need to disable this functionality on mobile when the hamburger menu button is clicked. How can I achieve this? Below is the cod ...

Provide input data to the function for delivery purposes

Creating a simple webpage with a form input that triggers a script to request JSON data from the server based on the user's input. The challenge is passing the value from the input field to a function for processing. var search = document.querySele ...

Modifying CSS stylesheet does not alter the background color

body { background-color: bisque; } <!DOCTYPE html> <html> <head> <title>Reading</title> </head> <body> <h1> <button><a href="index.html">Home</a></button> & ...

What is the best way to implement left padding in Bootstrap 5?

When transitioning from bootstrap4 to bootstrap5, we encountered an issue where the pl-5 class for left padding was no longer working properly. <div class="col-md-6 col-9 p-3 pl-5"> in bootstrap5 this code is not functional ...

Raycasting in three.js - mouse pointer and highlighting not precisely aligned with intersected mesh

My current setup involves using a raycaster to highlight a row of cubes arranged in a grid format. The highlighting works fine, but I'm encountering issues with the cursor turning into a pointer precisely over the cubes in the row. Moreover, the highl ...

Having trouble loading JSON data into jqGrid on a Spring 3 MVC application

How can I load a jqgrid with JSON data type on button click? I have tried various methods but the grid remains empty. What am I missing here? My Grid $("#bedata").click(function(){ jQuery("#list2").jqGrid({ url:'/mso/interop/interopcompa ...

Converting .html files to .php format using singleshot - A quick guide

I am looking for a quick way to convert hundreds of .html pages in my local folder to .php format. Is there a method to avoid manually replacing each ".html" with ".php" and execute the conversion in a single shot? ...

Bootstrap's Vertical Margin Concept

Is there a way to include margin or a line similar to the image below? [![Please refer to the accompanying image][1]][1] ...

Making an AJAX POST request with jQuery to a specific subdomain

I am experiencing difficulties with an Ajax Request across different SubDomains. The PHP Script responsible for handling the request can be found at account.domain.com/login Despite having multiple SubDomains, the Ajax request is accessible from all of t ...

Load Vue: Include jQuery globally for all components

When working with vue-loader single file components, I often need to use jQuery in specific components. To do this, I typically import jQuery like so: import $ from 'jQuery' Is there a way to import jQuery globally, making it available for all ...

What is the best method for incorporating conditional logic into Django forms?

In my quest to incorporate conditional logic into my Django model form, I have encountered more challenges than expected. My objective is simple: when a user selects option A, I want an additional question to appear; and when they choose option B, I want a ...

Could columns in flexbox be stretched? It's up for debate

When using the "old" flexbox implementation, I would typically employ -webkit-box-align: start; to prevent side by side columns from being the same length. However, I am struggling to achieve the same result with the new specification. More information ca ...

The 'getGridMerchantLocationData' function contains duplicate definitions for both DataSource and DataSourceID. Please remove one of the definitions

I am having trouble binding data from a dataset. Can someone review my code and point out where I may be going wrong? The current issue is that it's not binding and throwing an exception: "Both DataSource and DataSourceID are defined on 'getGridm ...