I have a container that contains two elements: a search bar, and a table under it. Inside the table, I have a sidebar to the left and some content to the right. The container has fixed height, and I want the sidebar and content to fill the space vertically.
I can get the table to fill the space, but not the sidebar and the content. This is the closest I can get:
* {
font-family: "Poppins", sans-serif;
}
body {
background-size: 100%;
/*background-image: url('./images/diego-ph-5LOhydOtTKU-unsplash.jpg');*/
background-color: black;
background-repeat: "no-repeat";
background-position: 0 0;
color: aliceblue;
margin: 0;
padding: 0;
}
.projects-table {
border-style: solid;
border-radius: 1rem;
border-width: 0.25rem;
border-color: slategrey;
margin-top: 5rem;
padding: 1rem;
height: 20rem;
display: flex;
flex-direction: column;
}
.projects-table .search {
opacity: 0.25;
color: white;
display: flex;
flex-direction: row;
justify-content: start;
align-items: center;
border-bottom: solid;
border-width: 0.1rem;
}
.projects-table .search img {
width: 1.25rem;
height: 1.25rem;
margin-right: 0.25rem;
}
.projects-table .projects-content {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: flex-start;
margin-top: 1rem;
flex-grow: 1;
border-style: solid;
}
.projects-table .projects-content .sidebar {
width: 10%;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
border-style: solid;
margin: 0.5rem;
}
.projects-table .projects-content .sidebar p {
border-style: solid;
border-width: 0.1rem;
border-radius: 0.5rem;
margin-top: 0;
margin-bottom: 0.5rem;
padding: 1rem;
}
.projects-table .projects-content .content {
width: 100%;
height: 100%;
margin: 0.5rem 1rem 0.5rem 1rem;
border-style: solid;
border-width: 0.1rem;
border-radius: 0.5rem;
padding: 1rem;
}
<div class="projects-table">
<div class="search">
<h3>Search...</h3>
</div>
<div class="projects-content">
<div class="sidebar">
<p>Sidebar</p>
<p>Sidebar</p>
</div>
<p class="content">content</p>
</div>
</div>
3
Answers
You can try to set flexbox
align-items:stretch
andflex-grow:1
properties:All you need to do is to give the content items a
flex-grow: 1
Here is a bit of an alternate way to do what you are doing. I find using something like this makes long-term maintenance easier and individual "block" styling easier to understand without complex positioning.
I find that using a grid with grids IN it makes complex layout easier. Note here I used some grid-areas names just to make things clear what was where; some ugly styling just to show what is where etc.