Flex-grow does not expand child divs
P粉388945432
P粉388945432 2024-02-03 18:18:58
0
1
351

I'm new to css and I need help with a problem. Why doesn't flex-grow expand the block__column_2 div to the end of the screen? According to curriculum theory, this should be expected behavior. Please tell me what am I doing wrong?

Code sample is shown below. Index.html style.css

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>flexbox</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="wrapper">
        <div class="block">
            <div class="block__row">
                <div class="block__column block__column_1">
                    <div class="block__item">1</div>
                </div>
                <div class="block__column">
                    <div class="block__item block__column_2">2
                        <br>Более высокий блок
                    </div>
                </div>
                <div class="block__column block__column_3">
                    <div class="block__item">3</div>
                </div>
            </div>
        </div>
    </div>
    
</body>
</html>

.wrapper{
    height: 100%;
    overflow: hidden;
    min-height: 100%;
    padding: 50px;
}
body{
    font-family: Arial, Helvetica, sans-serif;
}
    
.block__row{
    border: 20px solid #ece89d;
    margin: 0px 0px 20px 0px;
    display: flex;
    flex-direction: column;
    height: 1024px;
    align-items: stretch;       
}

.block__column{
border: 20px solid #5e5373;
}

.block__column_1{}
.block__column_2{  
    flex-grow: 1;
    flex-basis: auto; 
}
.block__column_3{}

.block__item{
    background-color: #18b5a4;
    padding: 50px;
    font-size: 50px;
    color: #fff;
    font-weight: 700;
text-align: center;
}

P粉388945432
P粉388945432

reply all(1)
P粉323050780

Remove block__column_2 class from div.block__item and add to div.black_column
and add display:flex for block__column The display: block attribute on the parent element prevents flex-grow from having any effect. Try setting the display: block property on the parent to display: flex. and add width:100%; to .block__item

2
Более высокий блок
.block__column{ border: 20px solid #5e5373; display: flex; } .block__column_1, .block__column_3{ flex-grow: 0; } .block__column_2{ flex-grow: 1; } .block__item{ background-color: #18b5a4; padding: 50px; font-size: 50px; color: #fff; font-weight: 700; text-align: center; width: 100%; }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template