How can I reorder my divs using only CSS?

后端 未结 24 1517
傲寒
傲寒 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 02:01

    As others have said, this isn't something you'd want to be doing in CSS. You can fudge it with absolute positioning and strange margins, but it's just not a robust solution. The best option in your case would be to turn to javascript. In jQuery, this is a very simple task:

    $('#secondDiv').insertBefore('#firstDiv');
    

    or more generically:

    $('.swapMe').each(function(i, el) {
        $(el).insertBefore($(el).prev());
    });
    

提交回复
热议问题