Home > Web Front-end > CSS Tutorial > How to Create Overlapping Flex Items in a Horizontal Row?

How to Create Overlapping Flex Items in a Horizontal Row?

Barbara Streisand
Release: 2024-10-29 09:03:02
Original
770 people have browsed it

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:



.cards {<br>  display: flex;<br>  align-content: center;<br>  max-width: 35em;<br>}</p>
<p>.cardWrapper {<br>  overflow: hidden;<br>}</p>
<p>.cardWrapper:last-child, .cardWrapper:hover {</p>
<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">overflow: visible;
Copy after login

}

.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;
Copy after login

}


  • 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.

The above is the detailed content of How to Create Overlapping Flex Items in a Horizontal Row?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template