As of now, there is no way that you can style a div (or any other element for that matter) dynamically on the basis of a previous element. But you have some options here –
- either you can use Javascript to manage the styles of elements dynamically, or,
- you can use CSS FlexBox Model or CSS Grid to position and change height/width of elements, which is highly recommended and super powerful for making any layout of your choice.
Here are some places which I used to learn flexbox –
freeCodeCamp flexbox tut
Brad Traversy flexbox crash course
Now for CSS grid-