Tips for organizing visuals in ReactJS using CSS in pairs of two

Utilizing Leaflet maps alongside recharts in a ReactJS environment, I have an issue where the PopUp displaying six charts vertically when clicking on a map marker. My goal is to style these charts into groups of two, arranged in three lines.

https://i.sstatic.net/khHi8.jpg

I am seeking guidance on how to use CSS to achieve this desired styling effect.

The code snippet in question is depicted below:

      {coords.map(({ lat, lng }, index) => (
          <Marker position={[lat, lng]} icon={customMarker} key={index}>
            <div className="popup">
            <Popup maxWidth="500" maxHeight="auto" >
              {index + 1} is for popup with lat: {lat} and lon {lng}
              ...
            </Popup>
            </div>
          </Marker>
        ))}
      </LeafletMap>

In order to integrate the desired grouping of <ComposedChart/> elements, two per line within three rows, I have attempted implementing CSS styles by importing an external stylesheet as shown below:

.popup {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: space-between;
  height: 100%;
}

.chart {
  width: 40%;
}

Despite applying these CSS rules, I am unable to observe the intended changes in the chart layout.

CodeSandBox

Answer №1

I'm a big advocate for utilizing the power of Flexbox. In this particular scenario, you can easily address the issue and make it responsive with just a few lines of CSS:

.popup {
  display: flex;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: space-between;
  height: 100%;
}

.chart {
  width: 40%;
}

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

When using Next.js, I have found that the global.css file only applies styles successfully when the code is pasted directly into the page.tsx file. However, when attempting to

I recently started exploring nextjs and came across this video "https://www.youtube.com/watch?v=KzqNLDMSdMc&ab_channel=TheBraveCoders" This is when I realized that the CSS styles were not being applied to HeaderTop (the first component cre ...

Is there an alternative method to handle the retrieval of JSON data without encountering numerous errors?

I'm currently in the process of instructing an LLM model to generate a blog. I used Mistral as the base model and set up an instruction to return JSON output. I then created a function that takes the prompt as an argument and returns generatedPosts as ...

Display the initial page and activate the first navigation button when the page loads

Greetings to everyone. I am new to the world of jquery and currently in the process of learning. This is my script: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"> </script> <script> $(function () { $ ...

Issues with expected identifiers and type mismatch errors encountered when defining a TypeScript class

As someone who is still relatively new to coding, I am facing a challenge while trying to create a TypeScript class within an Angular project that is based on a complex JSON file. The issue arises from the way the properties were defined in the JSON using ...

Unable to retrieve image: status code 402 - payment required

When trying to fetch my Facebook page's posts using the Facebook graph API and nextjs with vercel, I encountered an error: GET imageurl 402 payment required. Oddly enough, this works perfectly fine in localhost: https://i.sstatic.net/JGy2g.png I sus ...

Can you explain the purpose of the bson type in conjunction with the javascript/javascriptwithscope?

I am intrigued by the utilization of the two types of bson, specifically javascript and javascriptwithscope, as the foundational types of bson. What are the use cases for these types and how can a javascriptwithscope object be created and saved in mongodb ...

Bug found in Next.js 13 where all pages not rendering on the server side

All pages in the next 13 (experimental app.dir) are rendered on the server side. It doesn't matter if there is any data fetching inside them. Only slug pages with generateStaticParams are automatically generated as static. For example: app/te ...

How to use v-if in Quasar framework to hide a Vuejs component on the signup page

Currently, I am utilizing the Quasar drawer feature in my application. On the signup view, I would like to hide the drawer. While my current code successfully hides the drawer, an issue arises when I reload the signup page as it briefly renders in the DOM ...

Exploring methods for accessing JSON Array elements in react js using the filter function

Looking to extract the PartNumber of each item from a JSON array and store them in another array using filter method. Can anyone guide on how to achieve this? Here is the code snippet I have tried so far, but it only retrieves the PartNumber of the first ...

There is a type error: The term 'Post' is referencing a value when it is being used as a type here. Were you intending to use 'typeof Post' instead?

After creating a blog app using Nextjs + Sanity, I encountered an issue in my [slug].tsx file. The error message reads: Type error: 'Post' refers to a value but is used as a type here. Did you mean 'typeof Post'? The file has the .t ...

Distinguishing between a hidden input containing an "empty string" and one that is "null" in Javascript and VB

While attempting to JSON deserialize a collection in VB, I encountered the following issue. Dim items = JsonConvert.DeserializeAnonymousType(Page.Request.Params("Items"), New List(Of ItemDto)) An error occurred during deserialization where the string "va ...

What is the best way to reset the scroll position of a div when you stop hovering over a link?

Can anyone help me figure out how to reset the scroll wheel when hovering over dropdown menu items? I've tried multiple solutions found online, but none seem to be working for me. If you have any ideas on how to accomplish this, please let me know! f ...

Spin a jQuery-css animation by 90 degrees every time a button is clicked

I am facing an issue with rotating a div in my project. I have managed to partially achieve the desired functionality where pressing a button rotates the div by 90 degrees each time. However, when I try to rotate it further, the div reverts back to its ori ...

Struggling to manage texbox with Reactjs

Currently working in Reactjs with Nextjs and encountering a problem with the "text box". When I use the "value" attribute in the textbox, I am unable to input anything, but when I use the "defaultValue" attribute, I receive a validation message saying "Ple ...

Using JSON object as an argument in React functional component

Currently, I'm trying to assign a JSON object to a const variable. I've been successful with using vars in the past, like so: {this.props.user.map(function(user){... However, when it comes to stateless consts, I'm encountering some confusi ...

Can you please explain the significance of (session?._id)?

export default NextAuth({ ... callbacks: { session: async ({ session, token }) => { if (session?.user) { session.user.id = token.uid; } return session; }, jwt: async ({ user, token }) => { if (user) { ...

Utilizing numerous instances of setInterval

I've created a jsFiddle which can be found here: http://jsfiddle.net/dztGA/22/ Main Objective: My aim is to have two independent timers on the same page that can be stopped and restarted either by hovering or manually. The Issue: The problem illustr ...

Issues encountered during the installation of Electron JS

Having trouble installing electronjs in Node.js 18 LTS and NPM 10? Getting an error message like this? PS C:\Users\Administrator.GWNR71517\Desktop\electron> npm install electron --save-dev npm ERR! code 1 npm ERR! path C:\Users& ...

Using requestAnimationFrame and event listeners for keyup and keydown events in TypeScript

Having trouble getting requestAnimationFrame to work with event listeners keyup/down in a TypeScript class? It works fine outside the class. Can you help me figure out why it won't work inside a class? class GameEngine { private aKey:boolean ...

What methods can I use to ensure that the columns and rows in Vue are of the same size and length

Upon examining the image, it's clear that none of the columns and rows align properly and are all varying sizes. I am relatively new to JavaScript and Vue, so any assistance would be greatly appreciated. As far as my understanding from online resource ...