I
I
inavo2020-07-22 10:25:25
Bootstrap
inavo, 2020-07-22 10:25:25

How to move dropdown-menu to another block?

Suppose there is such a block

<div class="dropdown">
  <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    Dropdown button
  </button>
  <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
    <a class="dropdown-item" href="#">Action</a>
    <a class="dropdown-item" href="#">Another action</a>
    <a class="dropdown-item" href="#">Something else here</a>
  </div>
</div>


How can I separate the dropdown-menu block so that it looks like this:

<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    Dropdown button
</button>

<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
    <a class="dropdown-item" href="#">Action</a>
    <a class="dropdown-item" href="#">Another action</a>
    <a class="dropdown-item" href="#">Something else here</a>
</div>


It worked in bootstrap 3, but not in 4. In addition, the dropdown does not work without the dropdown-menu class.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
v1t3man, 2020-07-26
@inavo

in version 4 you can use data-toggle="collapse" for this, just replace dropdown with collapse.
And if you need data-toggle="dropdown", then you have to wrap it in a single div.

E
Evgeny Pashkov, 2020-07-22
@pashkoveval

What is it for you? It just seems to me that this is superfluous if you want to implement some kind of animation to display the block with links itself. It can be done like this too.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question