I've got a relative div with a width of 40%. After that there is a fixed div that needs to inherit this width.
So I set my html document to this:
<div class="sidebar"></div>
<div class="maincontent">
<div class="fixed--wrapper">
<div class="fixed--header">
</div>
</div>
</div>
And my css:
.sidebar {
width: 20%;
height: 100vh;
overflow: hidden;
position: fixed;
background-color: #000;
color: #fff;
float: left;
}
.maincontent {
float: right;
position: relative;
width: 80%;
background-color: #D00;
height: 300px;
}
.fixed--wrapper {
width: 40%;
position: relative;
float: left;
border-right: 1px solid rgba(0, 0, 0, 0.2);
height: 100%;
overflow-y: scroll;
background-color: #E00;
}
.fixed--header {
height: 60px;
width: inherit;
position: fixed;
z-index: 2;
background-color: #fff;
}
Now the problem arises that my fixed--header is like 8% bigger than the fixed--wrapper. To illustrate this view the following fiddle: https://jsfiddle.net/zj0Lpu0q/1/
I want my fixed--header to be 40% as well.
Sidenote: I know there are quiet the number of questions about this, but I couldn't find one that has a relative div with widths in percentages defined. Therefore I created this new question. If you could link me to another answer I'm happy as well.