I am attempting to create the following layout:

As you can see when I scroll, the alignment of the 1st and 3rd items has scrolled with the content. I need a way to get the first and third items to stay sticky to their respective sides. I also need this solution to be responsive as the container scales with screen size.
#container {
height: 300px;
width: 50%;
position: relative;
overflow: auto;
border: solid 1px black;
}
.item {
height: 500px;
width: 100px;
z-index: 5;
position: absolute;
background-color: red;
}
.item:nth-child(2) {
width: 800px;
z-index: 2;
background-color: green;
}
.item:nth-child(3) {
right: 0;
}
<div id="container">
<div class="item"> </div>
<div class="item"> </div>
<div class="item"> </div>
</div>
What I Am Actually Building This is a generalized problem. The actual problem I am trying to solve is that of a custom-built HTML table. The left and right items (red sections) are going to be containers for static (sticky) columns. With that being said, I need the constraints of the problem to stay the same. Changing the width of the item:nth-child(2) to 100% will not work. Wrapping the contents inside of the item:nth-child(2) in another div and adding overflow: auto to that div will not work because then the scrollbar will not be shared amongst the entire container like it is in my example.