How to make a div occupy the entire screen, superimposing the parent element?

Asked

Viewed 116 times

0

Eae galera blz. I am in need of a help with the following effect. I have a button that when clicking it opens a list. But I want this list to take the entire screen. Except that when there is the problem, when opening it simply goes to the limit of the parent element, I can’t define the size that makes it cover every page (body), it is simply limited to the parent element, would have something to do to solve it ? I’m wearing the bootstrap. Edit: can do without the Fixed display? to not have the scroll bar.

<!DOCTYPE html>
<html lang="pt-br">

<head>
    <!-- Meta tags Obrigatórias -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

    <title>Olá, mundo!</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

</head>

<body>


    <div class="container">
        <div class="row">

            <div class="col-6">
                <a class="btn btn-block nav-link" data-role="list">
                    <span>Open</span>
                </a>



                <ul class="list-unstyled bg-primary text-white" id="list">
                    <div class="row">
                        <div class="col-9">

                            <ul class="list-unstyled" id="list">
                                <li>
                                    <h3>teste1</h3>
                                    dassadasd dassadasd dassadasd dassadasd
                                </li>

                                <li>

                                    <h3>teste1</h3>
                                    dassadasd dassadasd dassadasd dassadasd
                                </li>


                                <li>
                                    <h3>teste1</h3>
                                    dassadasd dassadasd dassadasd dassadasd
                                </li>
                            </ul>

                        </div>

                        <div class="col-3">
                            <a class="btn btn-block pt-5 nav-link">Close</a>
                        </div>
                    </div>

                </ul>


            </div>
        </div>
    </div>




    <script>
        $("#list").hide();

        $(document).ready(function() {
            $(".nav-link").click(function() {
                $("#list").toggle();
            });
        });
    </script>



    <!-- JavaScript (Opcional) -->
    <!-- jQuery primeiro, depois Popper.js, depois Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>

</html>
  • "I can’t define the size that makes it cover every page" if you are inside another div and want to do this, wouldn’t it be better to open as a lightbox and occupy the whole screen? jquery has it ready

1 answer

0


I believe that this way that you are thinking will not be possible, but if you change a little the way of thinking should already get the desired result.

Instead of "open a list," you could

  • add an element to the DOM where necessary; or
  • Display a previously hidden item; or
  • Leave an "empty" element prepared to receive the content you want and display it;

All cases are similar in terms of encoding. Here is an example of how the last option could be made.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
    <div id="div_de_exemplo"></div>
    <a id="div_de_exemplo_close" style="display: none">close</a>

    <div class="container">
        <div class="row">

            <div class="col-6">
                <a class="btn btn-block nav-link" data-role="list" id="open">
                    <span>Open</span>
                </a>

                <ul class="list-unstyled bg-primary text-white" style="display: none">
                    <div class="row">
                        <div class="col-9">

                            <ul class="list-unstyled" id="list">
                                <li>
                                    <h3>teste1</h3>
                                    dassadasd dassadasd dassadasd dassadasd
                                </li>

                                <li>

                                    <h3>teste1</h3>
                                    dassadasd dassadasd dassadasd dassadasd
                                </li>


                                <li>
                                    <h3>teste1</h3>
                                    dassadasd dassadasd dassadasd dassadasd
                                </li>
                            </ul>

                        </div>
                    </div>

                </ul>


            </div>
        </div>
    </div>




    <script>
        $(document).ready(function() {
            $("#open").click(function() {
                $("#div_de_exemplo").html($( this ).next().html());
                $("#div_de_exemplo .ul").show();
                $("#div_de_exemplo").show();
                $("#div_de_exemplo_close").show();
                $("#open").hide();
            });
            
            $("#div_de_exemplo_close").click(function() {
                $("#div_de_exemplo_close").hide();
                $("#div_de_exemplo").hide();
                $("#div_de_exemplo").html("");
                $("#open").show();
            });
        });
    </script>
</body>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.