"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Create Overlapping Flex Items in a Horizontal Row?

How to Create Overlapping Flex Items in a Horizontal Row?

Published on 2024-11-08
Browse:292

How to Create Overlapping Flex Items in a Horizontal Row?

Creating Overlapping Flex Items

When creating a horizontal row of flex items that may exceed the available width, it's often desirable to have them overlap. By default, flexbox will shrink the items to fit the container.

Flexbox Approach

To achieve overlapping, we can utilize the following approach:



overflow: visible;

}

.card {

width: 10em;
min-width: 10em;
height: 6em;
border-radius: 0.5em;
border: solid #666 1px;
background-color: #ccc;
padding: 0.25em;

display: flex;
flex-direction: column;
justify-content: center;
align-items: center;

}


  • Wrap each flex item in a .cardWrapper div.
  • By default, set the .cardWrapper to have overflow: hidden. This will hide any overflow from the child .card.
  • Use :last-child or :hover to allow the last item or hovered items to display their overflow.
  • Set the .card items to have a fixed width and minimum width to prevent them from being shrunk.
  • Hide any overflow from the .card items using overflow: hidden.
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3