When I used Flexbox, I thought that width: 200%
would make an item twice the size of Flexbox, but it was wrong.Please tell me why this is happening, thank you.
<div style='width:50vw;margin:0 auto;display:flex;justify-content:center;align-items:center;border:1px solid black;'>
<div style='border:1px solid black;width:150%;
height:100%;overflow:auto;'>
<p> ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.
</p>
</div>
</div>
The flex item has the flex-shrink
property and the default value is 1. The flex-shrink
property is a factor that indicates how much the flex item shrinks to other flex items.
<'flex-shrink'>
This <number[0, ]]>
component sets flex-shrink
longhand and specifications the flex shrink factor, which determines how much the flex item will shrink relative to the rest of the flex items in the flexible containment is present.
This reduces the size of the flex item to the container size, so the flex item does not stick out.Therefore, setting the value of the flex-shirink
property to 0 solves this problem.
.container{
width —50vw;
margin:0 auto;
display:flex;
justify-content:center;
align-items:center;
border —1px solid black;
}
.item{
border —1px solid red;
width: 150%;
height —100%;
overflow —auto;
flex-shrink:0; /* Add */
}
<div class="container">
<div class="item">
<p> ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.
</div>
</div>
© 2024 OneMinuteCode. All rights reserved.