I am trying to learn the flexbox layout. I saw a tutorial speaks about flex-grow and flex-shrink classes and all provided examples in this course works fine with flex-direction: row.
I tried to apply them with flex-direction: column
, but it does not work as I wanted. I googled it, but I didn't find a suitable answer to grow a flex item when the direction is set it up as a column.
My code is below. Could anyone fix my CSS to get flex-grow/shrink work in column direction please?
html,
body {
padding: 0;
margin: 0;
font-family: arial, sans-serif;
}
.flex-container {
display: flex;
border:solid 4px #000;
flex-direction: column;
height: 100%;
}
.flex-item {
color: #eee;
font-size: 1.2em;
padding: 1em;
text-align: center;
justify-content: center;
flex-grow: 1;
}
.flex-item:nth-child(1) {
background-color: #A62E5C;
flex-grow: 3;
}
.flex-item:nth-child(2) {
background-color: #9BC850;
}
.flex-item:nth-child(3) {
background-color: #675BA7;
}
.flex-item:nth-child(4) {
background-color: #620542;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="container-fluid">
<div class="flex-container">
<div class="flex-item">Flex 1</div>
<div class="flex-item">Flex 2</div>
<div class="flex-item">Flex 3</div>
<div class="flex-item">Flex 4</div>
</div>
</div>
</body>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</html>