reversing z-index based from page render order

前端 未结 4 1197
遇见更好的自我
遇见更好的自我 2020-12-29 06:41

Example Markup:

Trigger

This is some content
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-29 07:13

    Shiny new CSS flexbox technology makes this a bit easier, but the downside is the actual content will be reversed. This doesn't have to be a big problem, it's just semantically weird.

    In short: wrap everything in a container with these styles:

    display: flex;
    flex-direction: column-reverse;
    

    See the fiddles for a working example (hover over the wrapper elements to see the action).

    It's useful if you don't want to rely on javascript to dynamically check z-indexes every time you update the content. If the

    elements are inserted on the fly (or any other reason specific styles cannot be set in advance) The CSS rules in the example should be enough to take care of the z-indexes IF you insert the
    s in reverse order.

    This is your current setup: http://jsfiddle.net/dJc8N/2/

    And this is the same HTML, with added CSS (notice the numbers in the

    tags): http://jsfiddle.net/Mjp7S/1/

    EDIT:

    The CSS I posted is probably not ready to be copy-pasted yet. This, however, is:

    display: -webkit-flex;
    display: -moz-flex;
    display: -ms-flex;
    display: -o-flex;
    display: flex;
    -webkit-flex-direction: column-reverse;
    -moz-flex-direction: column-reverse;
    -ms-flex-direction: column-reverse;
    -o-flex-direction: column-reverse;
    flex-direction: column-reverse;
    

提交回复
热议问题