J
J
jaygen2020-06-16 21:10:46
HTML
jaygen, 2020-06-16 21:10:46

How to visually place an element higher than it is in the page code?

There is a code:

<div>
<p>TEXT1</p>
<p>TEXT2</p>
<h2>NEW TEXT2</h2>
<p>TEXT2.1</p>
<p>TEXT2.2</p>
<div style="display:flex;">
<div>Схема работ</div>
<div>Форма</div>
</div>
</div>

How to place an element <div>Форма</div>in the mobile version so that it remains in the document code.. But it was before the heading < H2 >

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
nveretenko, 2020-06-17
@jaygen

For this case, you can solve without js

<div class="wrapper">
    <p class="item-1">TEXT1</p>
    <p class="item-2">TEXT2</p>
    <h2>NEW TEXT2</h2>
    <p>TEXT2.1</p>
    <p>TEXT2.2</p>
    <div class="container">
        <div>Схема работ</div>
        <div class="form">Форма</div>
    </div>
</div>

.wrapper {
  display: flex;
  flex-direction: column;
}

.container {
  display: contents;
}

.form, .item-1, .item-2 {
  order: -1;
}

A
archelon, 2020-06-16
@archelon

1. CSS
The basic principle is this: set the parent container

.wrapper {
display: flex;
flex-direction: column;
}

For child elements, set the appropriate order property
.form-block {
order: 1;
}
.heading-block {
order: 2;
}

The markup, of course, needs to be redone accordingly.
2. JS
Move element. For example:
$( '#form' ).appendTo( '#block' );

D
Dima Pautov, 2020-06-16
@bootd

negative margin

S
Sakhalinex, 2020-06-17
@Sakhalinex

.wrapper {
display: flex;
flex-direction: column-reverse;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question