I am trying to achieve a simple website layout with only 3 basic elements, but somehow can not make them work. I will be needing the layout work in 3 resolutions:
- Mobile
- Tablet
- Desktop
and the layout itself seems impossible for the resolutions.
Here is a picture of the elements and resolutions:
Elements explained:
- Header (not fixed height)
- Main content
- Right sidebar (fixed width)
I am using flexbox for the elements in all the resolutions and also I am wrapping them in a main container.
I am stuck getting the desktop resolution working. Where am I going wrong?
Here is a Codepen.
<div id="container">
<div class="el-1"><span>1<span></div>
<div class="el-2"><span>2<span></div>
<div class="el-3"><span>3<span></div>
</div>
/* mobile */
#container {
display: flex;
flex-wrap: wrap;
flex-direction: column;
}
.el-1 {
order: 0;
flex: 1 0 100%;
background: red;
}
.el-2 {
order: 1;
flex: 1;
background: green;
}
.el-3 {
order: 2;
background: blue;
}
/* tablets */
@media (min-width: 681px) {
#container {
flex-direction: row;
}
.el-2 {
order: 1;
}
.el-3 {
order: 2;
flex: 0 0 300px;
}
}
/* desktops */
@media (min-width: 1025px) {
/* help */
}
I am not sure if combining some of the elements in a wrap element will work. Every time I try to combine any 2 elements in a wrap, it seems to be impossible for some of the resolutons.
EDIT: I found the answer
/* desktops */
@media (min-width: 1025px) {
#container {
position: relative;
}
.el-1, .el-2 {
max-width: calc(100% - 300px);
}
.el-3 {
position: absolute;
height: 100%;
right: 0;
top: 0;
}
}