Concern with Isotope's masonry feature

I'm at my wit's end!

The container div I'm dealing with is 1170px wide. My goal is to fit in 3 divs within this width. The first div is 275px wide, the second is 580px wide, and the third is also 275px wide. Altogether, these divs should add up to a total width of 1130px.

No matter how much I adjust the width of the container div, I just can't seem to get that third div to align on the same line as the other two. It keeps dropping down.

My brain is on the verge of exploding from frustration. Please, someone help!

Sample HTML code:

<div class="container">
    <div class="row">
        <div class="grid">

            <div class="grid-item">
                <img src="img/portfolio1.jpg" alt="">
            </div>

            <div class="grid-item width-double">
                <img src="img/portfolio2.jpg" alt="">
            </div>

            <div class="grid-item">
                <img src="img/portfolio3.jpg" alt="">
            </div>

        </div>
    </div>
</div>

CSS snippet:

.grid {

    .grid-item {
        padding: 0;
        width: 275px;
        height: 275px;
        float: left;

        &.width-double {
            width: 580px;
        }

        &.height-double {
            height: 580px;
        }
    }

}

Javascript function:

$grid.isotope({
     itemSelector: '.grid-item',
     layoutMode: 'masonry'
});

Check out the code here: http://codepen.io/anon/pen/meORoL

Answer №1

View Demo

var $grid = $('.grid');
$grid.isotope(
{
      itemSelector: '.grid-item',
      masonry: 
      {
          columnWidth:1
      }
});

Remember to specify the width of the columns as needed for your layout.

Answer №2

Although Diptox's solution seems to work, there could be a better approach to handling this issue.

In an ideal scenario, you would manually define the columnWidth. However, if it is not set, Masonry will base it on the size of the first item in the grid. The problem arose because the larger item in the grid was not a perfect multiple of the width of the first item. With a width of 580px as opposed to the first item's 275px, the larger item did not align properly within the column array established by Masonry. If its width had been a multiple of 275px, like 550px (275 * 2 = 550), it would have displayed correctly.

I am unsure whether setting the columnWidth to 1 poses any concerns, but intuitively it may not be the optimal choice since it is the default value -- though it might not cause any issues after all.

Edit: I forgot to include the code snippets

CSS:

.grid-item.width-double {
  width: 550px;
}

Javascript:

$grid.isotope({
  itemSelector: '.grid-item',
  masonry: {
        columnWidth: 275,
    }
});

Check out the demonstration on CodePen here!

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

Leverage React Context beyond the confines of a React component

The React Context API has impressed me, but I often find myself struggling to access it outside of a React component. Everything works smoothly within a React function or class component, but when it comes to fetching a value from the context for tasks lik ...

Adding a navigation bar to every administrator page while excluding it from shop pages can be achieved by creating a

I am facing a challenge in implementing a navbar and sidebar on all admin pages, except for the shop page. The issue arises because I have set my sidebar and navbar to be global. My goal is to make them global only for admin pages and not for the shop. He ...

Identifying the user's location within the application and dynamically loading various Angular scripts

Currently, I am working on a large-scale web application using Laravel and Angular. In this project, I have integrated various angular modules that come with their own controllers, directives, and views. One challenge I am facing is the need to load diffe ...

Attempting to save the result of a fetch call into a variable for the purpose of rendering it as a list in a

I'm attempting to fetch the top 5 NFT collections based on volume and display them in a table format. However, I'm facing an issue where the data is not being mapped correctly and when I click the "get" button, all content on the webpage disappea ...

The value from the textbox is not being received by the JavaScript and PHP

I'm encountering an issue with my codes where they are not properly passing the value of the verification code from the textbox to JavaScript and then to PHP. I need assistance in resolving this issue. Below is the snippet of code: HTML: /* HTML c ...

No content in a DIV element causing unusual height in IE7

UPDATE 1: After some experimenting, I discovered that by removing the width:100% property from the div, I am able to achieve the desired outcome of having a height of 0 when the div is empty. However, I still require the div to have a width of 100%, which ...

The process of exporting and utilizing models in Sequelize

When working on my node.js project with sequelize, I encountered a challenge of exporting and using table models in another file. I typically save table models in a folder, for instance Profile.js. module.exports = (sequelize, DataTypes) => sequelize.d ...

Adjusting the size of <nav> element to accommodate its child elements

I've exhausted all possible CSS solutions today in an attempt to make my parent nav tag home-main-nav-menu resize based on its children and grandchildren, but it just won't cooperate. If anyone could provide a clear explanation on how to solve th ...

Using Node.js with the express framework for requiring and posting data

main.js: var mainApp = express(); require('./new_file.js')(mainApp); new_file.js: mainApp.post('/example', function(req, res) { console.log(true); }); Error message: mainApp is not defined. Looking for a solution to access exp ...

What is the reason behind the perpetual hiding of the button?

<div class="app__land-bottom" v-if="isVisible"> <a href="#projects"> <img ref="arrowRef" id="arrow" src="./../assets/down.png" alt srcset /> </a> </div> When ...

Upon successful authorization, the Node Express server will pass the access token to the React client app via OAuth in the callback

I am currently working on a node server that authenticates with a third party using oauth, similar to how Stack Overflow does. After authorizing the request and obtaining the access token and other essential information from the third party, my goal is to ...

Div with sidebar that sticks

I am currently working on setting up a website with a sticky sidebar. If you would like to see the page, click this link: On a specific subpage of the site, I am attempting to make an image Validator sticky, but unfortunately, it's not functioning a ...

Generating text upon clicking by utilizing vue apex charts dataPointIndex

Is there a way to populate a text area on click from an Apex chart? The code pen provided below demonstrates clicking on the bar and generating an alert with the value from the chart. Instead of displaying this value in an alert, I am looking to place it o ...

Arranging content within a bounding box

Hello everyone, I'm currently working on creating a webpage layout with a main container that will house all the content. Inside this container, I have an image covering a specific portion of it, a title positioned to the left, and text to the right. ...

Having trouble with jQuery not functioning properly in IE9 when trying to add items to a List

I've created a listbox that allows users to add or remove items. To add an item, they can enter text in a textbox and click the "Add" button, which will prepend the text to the top of the list if it's not already present. I used jQuery to handle ...

Storing data locally in Angular applications within the client-side environment

As I delve into Angular and TypeScript, I've encountered a perplexing issue. Let's say I have two classes - Employee and Department. On the server-side, I've established a Many-To-One relationship between these entities using Sequelize: db. ...

There seems to be a complete absence of rendering in this particular vue

Upon initializing a fresh Vue project using Vue CLI 3 and removing all default views and components, I proceeded to add two new views. To my surprise, these views did not render when changing the URL; instead, I was met with a blank page and no error messa ...

Leverage the URL parameter with variables in HTML using AngularJS

I'm facing the same issue as yesterday: trying to extract and utilize parameters from the URL within my HTML page using AngularJS. What am I doing wrong? The parameter I need to work with is: https://url.com/index.html?user I aim to retrieve the "u ...

The functionality of Access-Control-Allow-Origin is not effective in Chrome, yet it operates successfully in Firefox

I'm facing an issue with my code in the HTML file. I have a second file that I want to load content from, and both files are located in the same directory <div id="mainMenu"></div> <script> $(function() { $('#mainMe ...

Unexpected behavior encountered when implementing specific Textfield validation with Material UI

Currently running a project on Node and utilizing React for the front-end, I have encountered an issue with setting .env variables. The project is built with Material UI, and most TextFields are working as expected with their specified validation rules. ...