Solution 1 :

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-

Brad Traversy CSS Grid

freeCodeCamp CSS Grid

Problem :

I am very new to CSS..

I would like to know if there is a way to dynamically position a div element based on the length of the previous div element.

Example:

<div id="A">
</div>

<div id="B">
</div>

<div id="C">
</div>

If these div elements were full width each and i want one to come after the other based on the length of the previous one without adjusting the length on the top property myself.

Is this possible or is there any top value that can be used?

Thank you so much.

By

Leave a Reply

Your email address will not be published. Required fields are marked *