I don't succeed in limiting the height of a HTML element inserted inside a 'flex-direction: column' container. I would like to have a window with:
- on the top, the title of my page
- on the left, some commands
- on the right, a list on which I can interfer
The .list
box should be limited in height (the height of its ancestor), and I should be able to scroll (probable with some kind of overflow: auto
).
The problem, as I saw in the inspector, is that the element .tabcontent
is not limited in height. It overflows its parent (.namespace
). The thing is, I think, that I don't succeed in limiting the size of flex children when they are in the main direction.
//* Artificial filling.
const list = document.querySelector('.list');
for (i = 0; i < 100; i++) {
list.appendChild(Object.assign(document.createElement('p'), {
innerHTML: i,
}));
}
html {
height: 100%;
display: flex;
}
body {
overflow: hidden;
flex-grow: 1;
display: flex;
}
.tabsholder {
flex-grow: 1;
display: flex;
}
.namespace {
flex-grow: 1;
display: flex;
flex-direction: column;
}
.titlesline {
font-size: 50px;
}
.tabcontent {
flex-shrink: 1;
}
.needs {
display: flex;
gap: 10px;
}
.controls {
display: flex;
flex-direction: column;
}
.list {
overflow: auto;
}
<body>
<div class='tabsholder'>
<div class='namespace'>
<div class='titlesline'>titles line</div>
<div class='tabcontent'>
<div class='needs'>
<div class='controls'>
<button>ajouter</button>
<button>supprimer</button>
<button>déplacer</button>
<button>sauvegarder</button>
<button>charger</button>
</div>
<div class='list'></div>
</div>
</div>
</div>
</div>
</body>