Overlap of columns within a nested flexbox arrangement

While working with React and Styled Components, I encountered a problem of elements overlapping each other:

https://i.stack.imgur.com/RuCYu.png

There are a few instances of overlap, including:

  • The padding below the <ul> element is colliding with the button positioned beneath it (which is a React Router Link represented by an <a> tag).
  • The 'Request Quote' Link is getting overlapped with the <h2> right below it.

Upon inspecting the code snippet provided below, it's evident that the <div> containing the <ul> and <a> children (configured as a flex column) has a shorter height than the sum of its children, causing it to collapse in some way (if that's the appropriate term).

Interestingly, the <h2> and the said <div>, which were pointed out earlier, do not actually overlap when considering the height of the div container.

I've scoured for solutions on how to prevent this overlap issue but couldn't find any precise explanations for this scenario.

Question: Can someone provide insights on how to properly display these elements without overlaps?

The following represents the code structure corresponding to the aforementioned image:

Highlighted below is only the crucial part of the code; the full code will be shared subsequently.

...

const CartHeaderContainer = styled.div`
  display: flex;
  flex-direction: column;
  padding: 8px;
`;

const HeaderSubContainer = styled.div`
  flex-direction: column;

  @media (orientation: landscape) {
    flex-direction: row;
  }
`;

const H1 = styled.h1`
  font-size: 1.3rem;
  margin: 0 0 0.5rem 0;
`;

const H2 = styled.h2`
  font-size: 1.1rem;
  margin: 0;
`;

...

<CartHeaderContainer>
  <H1>Shopping cart</H1>
  <HeaderSubContainer>
    <List
      data={[
        {
          title: "Products in cart:",
          value: this.props.cartProducts.length
        },
        { title: "Total price:", value: `€ 10000` }
      ]}
      titleKeyName="title"
      valueKeyName="value"
    />
    <ButtonLink to={`/${this.props.match.params.locale}/order/`}>
      Request Quote
    </ButtonLink>
  </HeaderSubContainer>
  <H2>Products in cart:</H2>
</CartHeaderContainer>
...

Answer №1

I made a modification by replacing the React Router Link element with a <button> and handling the route change programmatically.

This adjustment resolved any overlapping issues I was experiencing.

Here is the code snippet that I implemented:

<Button
  onClick={() => {
    this.props.history.push(
      `/${this.props.match.params.locale}/order/`
    );
  }}
>
  Request quote
</Button>

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

Display a snippet of each employee's biography along with a "Read More" button that will expand the content using Bootstrap, allowing users to learn more about each team

I have successfully developed a Google App Script that links to a Google Sheet serving as a database. The application iterates through each row, and I showcase each column as part of an employee bio page entry. ex. Picture | Name | Title | Phone | Email ...

What does the concept of "installing packages globally or locally" entail in React JS?

I recently began learning React.js and as I was setting up the environment, I came across a confusing term: installing packages globally versus locally. What exactly does it mean to install packages globally versus locally in this context? ...

Try utilizing an image to hold text content rather than a traditional div container

I am seeking help with displaying a brief image description at the bottom of an image. Currently, the display looks like this: https://www.bootply.com/render/Gwde8WHtot However, I would like the green background to align with the actual image rather than ...

The visibility of buttons can be controlled based on the selected radio option

I have just completed setting up 4 buttons (add, edit, delete, cancel) and a table that displays data received via ajax. Each row in the table contains a radio button identified by the name "myRadio". When a radio button is clicked, I need the buttons to ...

Define the total in a CSS attribute

I am working with multiple divs that have a specific CSS class applied to them. My goal is to manually increase the pixel value in the top property: .class { top: 100px; } div class="class" style="top:+=50px" Is it possible to achieve this functiona ...

What is the best method to smoothly navigate to a specific id on a webpage after conducting a search using

I want to implement a jQuery function that allows me to scroll down to an id containing search results. The script as a whole, minus the JS, is functioning properly. I just need assistance in creating a method to search for specific id values. Below is my ...

It appears that Serverworker is causing significant delays in processing ajax requests

I'm encountering some performance issues with my PHP app that utilizes a lot of JavaScript for AJAX requests back to the PHP server. I'm currently implementing a service worker to cache content and enable push notifications, but I'm facing d ...

The useEffect hook is executed only once and will not fetch data again upon refreshing the page

There's this component in my project that fetches data from a website and attempts to extract its keys. The issue I'm facing is that it functions correctly the first time, but upon refreshing the page or saving the project in VSCode (which trig ...

Tips for eliminating repetitiveness in situations such as BEM modifiers

As I delved into using my own adaptation of the BEM methodology, I encountered a roadblock with modifiers for nested elements. The challenge at hand is changing the link color to red when product-desc-name has the mark class. The snippet below illustrat ...

What is the process to replace the image in these templates?

I recently downloaded a template from the internet and am in the process of developing a website. Can someone please guide me on how to change the icons highlighted in the black and red boxes as shown in the image? I am using Visual Studio and ASP.NET fo ...

Steps for loading a different local JavaScript file by clicking on a button

My goal is to reload the browser page and display a different ReactJS component/file when a button is pressed. Initially, I attempted using href="./code.js" or window.location="./code.js" within the button props, but unfortunately, it did not yield the des ...

The mysterious impact of ellipsis on MUI text fields

Is there a way to add an ellipsis effect on MUI textfields? I know they have a multi-line option for text wrap, but I'm looking for a way to limit it to a single line and have the text wrap with ellipsis similar to what you can do with <Text number ...

Encountered a TypeError when trying to access the 'subroute' property of an undefined object during JEST and enzyme testing

Currently, I'm utilizing jest along with the enzyme library for testing React components using the create-react-app boilerplate. After running the test suite, I encountered the following error: I haven't been able to find a solution to this issu ...

I am unable to modify the suffix located beneath the price of the product

Although I am not well-versed in PHP, I managed to create a code to display parcel descriptions below the price of products. The issue I am facing is that my code is calculating too many decimal places and not displaying the default currency, which should ...

Struggling to incorporate logout feature with node and passport js

Currently delving into the world of node js, I am in the process of creating a boilerplate utilizing passport js, react, and redux. The issue at hand involves trouble implementing log out functionality as my attempts to log out have been unsuccessful. Anyo ...

Generating a download link with an expiration feature in node.js or express for both frontend and backend operations

Hello everyone, I'm a beginner here and have recently started working with node.js and express.js. I am looking to implement a download link on my website that expires after a certain time, but I've been struggling with the code for about a week ...

Is there a way to apply textTransform to all components across the board?

I need to ensure that all text in my muiv5 project is capitalized by default, unless specifically overridden using sx or individual component styling. My attempted solution: <ThemeProvider theme={theme}> <IntlProvider locale="en& ...

"Vue3 offers the ability to return a multi-layer object through the Provide-Inject

While implementing provide-inject in my personal project, I encountered an issue where the value returned by inject() was a RefImpl Object. This meant that I had to access the actual value using inject().value.value instead of just inject().value. Here is ...

What causes axios to return a z_buf_error?

I've encountered an issue with axios returning an error cause: Error: unexpected end of file at BrotliDecoder.zlibOnError [as onerror] (node:zlib:189:17) { errno: -5, code: 'Z_BUF_ERROR' I'm puzzled as to why this functio ...

What is the best way to assign a value to react-select when working with grouped options?

Is there a way to update the value of a react-select component that has grouped options, as discussed in this post? Responding to @Tholle's comment: I didn't mention that I'm using Typescript because it might limit the number of responses. ...