Creating A Sidebar Within A Flexbox With Css
on my page I want to have a header and below this I want to have a sidebar on the left side and the content page on the right side. The sidebar should have a width of X (maybe 100
Solution 1:
You can set the height and width in a flexible way.
- Height is set to 100% of the height of the viewport minus the height of the header.
- Width is set to 100px for the sidebar. The content is now allowed to grow to fill the rest of the screen.
Hope this helps.
html {
height: 100%;
}
body {
height: 100%;
margin: 0;
font-family: Ubuntu;
background: linear-gradient(#b3ffab, #67fffc);
}
#header {
height: 30px;
display: flex;
align-items: center;
background: linear-gradient(#444444, #333333);
color: #bbbbbb;
}
#headerContent {
margin-left: 10px;
}
#page {
display: flex;
height: calc( 100vh - 30px);
/* calculate the height. Header is 30px */
}
#sideBar {
width: 100px;
background: red;
}
#content {
background: blue;
flex: 10 auto;
/* enable grow, disable shrink */
}
<linkrel="stylesheet"type="text/css"href="//fonts.googleapis.com/css?family=Ubuntu" /><divid="header"><divid="headerContent">
Desktop
</div></div><divid="page"><divid="sideBar"><div>
box 1
</div><div>
box 2
</div></div><divid="content">
content
</div></div>
Post a Comment for "Creating A Sidebar Within A Flexbox With Css"