How can I reorder my divs using only CSS?

后端 未结 24 1705
傲寒
傲寒 2020-11-22 01:53

Given a template where the HTML cannot be modified because of other requirements, how is it possible to display (rearrange) a div above another div

24条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 01:59

    If you know, or can enforce the size for the to-be-upper element, you could use

    position : absolute;
    

    In your css and give the divs their position.

    otherwise javascript seems the only way to go:

    fd = document.getElementById( 'firstDiv' );
    sd = document.getElementById( 'secondDiv' );
    fd.parentNode.removeChild( fd );
    sd.parentNode.insertAfter( fd, sd );
    

    or something similar.

    edit: I just found this which might be useful: w3 document css3 move-to

提交回复
热议问题