Bootstrap menu Collapse above the text

Asked

Viewed 275 times

1

I’m creating a website that, when accessed by mobile, your horizontal menu is compressed (Collapse), as shown in the image below:

Imagem 1

However, after I click on the menu symbol, the options appear above the page text and therefore it is not possible to click on them. Below I put an image of what happens:

Imagem2 What I would like to happen is that the green stripe expands, presenting the menu options and "push" the text from the home page down.

I am using version 4.3.1 of Bootstrap and my pages are composed of three sections, each with its corresponding file, one unique to the header (header.php), another to the content (home.php) and the last to the footer (footer.php). All these files are tied to a.php index..

Below, I place the code of each section.

index php.

    <?php 

include 'db.php';

include 'header.php';

if(isset($_GET['pagina'])){
    $pagina = $_GET['pagina'];
}
else{
    $pagina = 'home';
}

if($pagina == 'pesquisar'){
    include 'pesquisar.php';
}

if($pagina == 'inicio'){
    include 'views/home.php';
}

include 'footer.php';

header.php

<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width-device-width, initial-scale=1">
    <title></title>

    <link rel="stylesheet" href="css/bootstrap.min.css">

</head>

<body>
        <div class="container-fluid">
            <div class="row bg">
                <div class="col-12">
                    <nav class="navbar navbar-light navbar-expand-lg">
                        <a class="navbar-brand" href="?pagina=inicio">
                            <img src="img/logo2.png" width="200" height="40"
                                 class="d-inline-block align-top">
                        </a>
                        <button class="navbar-toggler" type="button" data-toggle="collapse"
                                data-target="#nav1" aria-controls="nav1" aria-expanded="false" aria-label="Navegação Toggle">
                            <span class="navbar-toggler-icon"></span>
                        </button>
                        <div class="collapse navbar-collapse" id="nav1">
                            <ul class="navbar-nav">
                                <li class="nav-item">
                                    <a href="?pagina=inicio" class="nav-link">Início</a>
                                </li>
                                <li class="nav-item">
                                    <a href="?pagina=quem_somos" class="nav-link">Saiba mais!</a>
                                </li>
                                <li class="nav-item">
                                    <a href="?pagina=placar" class="nav-link">Placar</a>
                                </li>
                                <li class="nav-item">
                                    <a href="?pagina=contato" class="nav-link">Contato</a>
                                </li>

                                <?php if (!$_SESSION['usuario'] || $nivel == membro) {} else { ?>
                                    <li class="nav-item">
                                        <a href="?pagina=pesquisar" class="nav-link"> Pesquisar</a>
                                    </li> 
                                <?php } ?>

                                 <?php if (!$_SESSION['usuario']) {} else { ?>
                                    <li class="nav-item">
                                        <a href="?pagina=anunciar" class="nav-link"> Anunciar</a>
                                    </li>
                                <?php } ?>

                                <?php if (!$_SESSION['usuario']) {} else { ?>
                                    <li class="nav-item">
                                        <a href="?pagina=perfil" class="nav-link"> Perfil</a>
                                    </li>  <?php } ?>
                                <?php if (!$_SESSION['usuario'] || $nivel == membro) {} else { ?>
                                    <li class="nav-item">
                                        <a href="?pagina=efigs" class="nav-link"> E-Figs</a>
                                    </li> <?php } ?>
                                <?php if (!$_SESSION['usuario']) {} else { ?>
                                    <li class="nav-item">
                                        <a href="logout.php" class="nav-link"> Sair</a>
                                    </li> <?php } ?>
                        </ul>
                        </div>
                    </nav>
                </div>
            </div>
        </div>

    <script src="js/jquery-3.2.1.min.js"></script>
    <script src="js/popper.min.js"></script>
    <script src="js/bootstrap.min.js"></script>

</body>

home php.

<html>

<head>

</head>

<body>

    <div class="container">
        <div class="row">
            <div class="col-sm-6 order-1">
                <?php if (!$_SESSION['usuario']) { ?>    
                    <br>
                    <h1 align="left">Bemindo!</h1>
                    <p align="left">Aquirro!</p>
                    <p align="left">Noselas!</p>
                    <br>
                    <img src="img/intro.png" title="Como Funciona?" alt="Como Funciona?" 
                         width="500" 
                         height="300"
                         class="img-fluid">

                <?php } else { ?>

                    <br>
                    <h2>Cfig.</h2>
                    <br>
                    <p>Leas.</p>
                    <br>
                    <p>Foara!</p>
                    <br>
                    <p>so:</p>
                    <br>

                    <div class="row" align="center">
                        <figure>
                        <img src="img/comum.png" title="Como Funciona?" alt="Como Funciona?" 
                         width="100" 
                         height="160">  
                        <figcaption align="center">Comum</figcaption></figure> &nbsp;

                        <figure>
                        <img src="img/incomum.png" title="Como Funciona?" alt="Como Funciona?" 
                         width="100" 
                         height="160">
                        <figcaption align="center">Incomum</figcaption></figure> &nbsp;

                        <figure>
                        <img src="img/intermed.png" title="Como Funciona?" alt="Como Funciona?" 
                         width="100" 
                         height="160"> 
                        <figcaption align="center">Intermediário</figcaption></figure> &nbsp;

                        <figure>
                        <img src="img/rara.png" title="Como Funciona?" alt="Como Funciona?" 
                         width="100" 
                         height="160">  
                        <figcaption align="center">Raro</figcaption></figure> 
                    </div>

                <?php } ?>
            </div>
            <div class="col-sm-6 order-2">
                <?php if (!$_SESSION['usuario']) { ?>

                    <br><br>
                    <h2 align="center">Faça seu Login:</h2>
                    <br>
                    <form method="POST" action="login.php" align="center">
                        <input type="text" name="usuario" id="usuario" placeholder="E-mail">
                        <br><br>
                        <input type="password" name="senha" id="senha" placeholder="Senha">
                        <br><br>
                        <input type="submit" value="Login" name="login" id="login">
                    </form>
                    <br>
                    <p style="font-size:12px" align="center">Não possui cadastro? Clique <a href="?pagina=cadastro">aqui</a>!</p>

                <?php } else { ?>

                    <br><br>
                    <h2>Inserir:</h2>
                    <br><br>
                    <form method="post" action="processa_dados.php" enctype="multipart/form-data">
                        <input type="file" name="imagem">

                        <input type="submit" value="Enviar">
                        <br>
                    </form>
                                <?php } ?>
            </div>
        </div>
    </div>

</body>

footer.php

<html>
<head>
    <style type="text/css">
        div.bg{
            background-color: darkseagreen;
            height: 60px;
        }
        p.fonte{
            font-size:10px;
        }
    </style>
</head>
<body>
    <br>
</body>
<footer>

    <div class="container-fluid">
        <div class="row bg">
            <div class="col" align="center">
                <p class="fonte">Apoio:</p>
            </div>
            <div class="col" align="center">
                <p class="fonte">Este site está em contínua melhoria</p>
            </div>
            <div class="col" align="center">
                <p class="fonte">Contato:</p>
                <br>
                <p></p>
            </div>
        </div>
    </div>
</footer>

  • Testing here your code already does it (see here). Where you are placing text that comes under the Nav?

  • What would that class be bg?

  • Dude put the code so at least we can simulate your problem, the way it is there has no way to answer you right...

  • Hello, thanks for all the suggestions! I put more information in the question... Basically, the page is structured in an index page (index.php), divided into header, body and footer. The text below Nav is found in the home.php file, while the header is in header.php. Sam, about the bg class, I created it to make the bottom of the header green. I appreciate any suggestion to enrich the question... I’m still new to stackoverflow.

1 answer

0


Your problem is you limited the size of nav with a height de 60px. That way when the content expands it goes out of the nav. Kind that the nav does not grow together pq is limited at 60px, there is no way to push the rest of the content down since it will always have 60px.

A tip I give you if you want to increase the Nav height is to put a margin on the logo, for example using the native Bootstrap margin class to give a space above and below, my-5 in img.logo.

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" media="screen" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.2/css/all.min.css" />
<style>
    div.bg {
        background-color: darkseagreen;
        /* height: 60px; */
    }

    p.fonte {
        font-size: 10px;
    }

</style>
</head>

<body>

    <div class="container-fluid">
        <div class="row bg">
            <div class="col-12">
                <nav class="navbar navbar-light navbar-expand-lg">
                    <a class="navbar-brand" href="?pagina=inicio">
                        <img src="img/logo2.png" width="200" height="40" class="d-inline-block align-top  my-5">
                    </a>
                    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#nav1" aria-controls="nav1" aria-expanded="false" aria-label="Navegação Toggle">
                        <span class="navbar-toggler-icon"></span>
                    </button>
                    <div class="collapse navbar-collapse" id="nav1">
                        <ul class="navbar-nav">
                            <li class="nav-item">
                                <a href="?pagina=inicio" class="nav-link">Início</a>
                            </li>
                            <li class="nav-item">
                                <a href="?pagina=quem_somos" class="nav-link">Saiba mais!</a>
                            </li>
                            <li class="nav-item">
                                <a href="?pagina=placar" class="nav-link">Placar</a>
                            </li>
                            <li class="nav-item">
                                <a href="?pagina=contato" class="nav-link">Contato</a>
                            </li>

                            <?php if (!$_SESSION['usuario'] || $nivel == membro) {} else { ?>
                            <li class="nav-item">
                                <a href="?pagina=pesquisar" class="nav-link"> Pesquisar</a>
                            </li>
                            <?php } ?>

                            <?php if (!$_SESSION['usuario']) {} else { ?>
                            <li class="nav-item">
                                <a href="?pagina=anunciar" class="nav-link"> Anunciar</a>
                            </li>
                            <?php } ?>

                            <?php if (!$_SESSION['usuario']) {} else { ?>
                            <li class="nav-item">
                                <a href="?pagina=perfil" class="nav-link"> Perfil</a>
                            </li> <?php } ?>
                            <?php if (!$_SESSION['usuario'] || $nivel == membro) {} else { ?>
                            <li class="nav-item">
                                <a href="?pagina=efigs" class="nav-link"> E-Figs</a>
                            </li> <?php } ?>
                            <?php if (!$_SESSION['usuario']) {} else { ?>
                            <li class="nav-item">
                                <a href="logout.php" class="nav-link"> Sair</a>
                            </li> <?php } ?>
                        </ul>
                    </div>
                </nav>
            </div>
        </div>
    </div>

    <div class="container">
        <div class="row">
            <div class="col-sm-6 order-1">
                <?php if (!$_SESSION['usuario']) { ?>
                <br>
                <h1 align="left">Bemindo!</h1>
                <p align="left">Aquirro!</p>
                <p align="left">Noselas!</p>
                <br>
                <img src="img/intro.png" title="Como Funciona?" alt="Como Funciona?" width="500" height="300" class="img-fluid">

                <?php } else { ?>

                <br>
                <h2>Cfig.</h2>
                <br>
                <p>Leas.</p>
                <br>
                <p>Foara!</p>
                <br>
                <p>so:</p>
                <br>

                <div class="row" align="center">
                    <figure>
                        <img src="img/comum.png" title="Como Funciona?" alt="Como Funciona?" width="100" height="160">
                        <figcaption align="center">Comum</figcaption>
                    </figure> &nbsp;

                    <figure>
                        <img src="img/incomum.png" title="Como Funciona?" alt="Como Funciona?" width="100" height="160">
                        <figcaption align="center">Incomum</figcaption>
                    </figure> &nbsp;

                    <figure>
                        <img src="img/intermed.png" title="Como Funciona?" alt="Como Funciona?" width="100" height="160">
                        <figcaption align="center">Intermediário</figcaption>
                    </figure> &nbsp;

                    <figure>
                        <img src="img/rara.png" title="Como Funciona?" alt="Como Funciona?" width="100" height="160">
                        <figcaption align="center">Raro</figcaption>
                    </figure>
                </div>

                <?php } ?>
            </div>
            <div class="col-sm-6 order-2">
                <?php if (!$_SESSION['usuario']) { ?>

                <br><br>
                <h2 align="center">Faça seu Login:</h2>
                <br>
                <form method="POST" action="login.php" align="center">
                    <input type="text" name="usuario" id="usuario" placeholder="E-mail">
                    <br><br>
                    <input type="password" name="senha" id="senha" placeholder="Senha">
                    <br><br>
                    <input type="submit" value="Login" name="login" id="login">
                </form>
                <br>
                <p style="font-size:12px" align="center">Não possui cadastro? Clique <a href="?pagina=cadastro">aqui</a>!</p>

                <?php } else { ?>

                <br><br>
                <h2>Inserir:</h2>
                <br><br>
                <form method="post" action="processa_dados.php" enctype="multipart/form-data">
                    <input type="file" name="imagem">

                    <input type="submit" value="Enviar">
                    <br>
                </form>
                <?php } ?>
            </div>
        </div>
    </div>



    <footer>

        <div class="container-fluid">
            <div class="row bg">
                <div class="col" align="center">
                    <p class="fonte">Apoio:</p>
                </div>
                <div class="col" align="center">
                    <p class="fonte">Este site está em contínua melhoria</p>
                </div>
                <div class="col" align="center">
                    <p class="fonte">Contato:</p>
                    <br>
                    <p></p>
                </div>
            </div>
        </div>
    </footer>

    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
</body>

</html>

  • Hugo, I made the change and it worked exactly the way I wanted it! Thank you so much for your reply!

  • @Pedroschimmelpfeng if it has helped you in any way consider marking the question as you accept in this icon below the little arrows next to my answer. Hhaha It was worth the young force!

Browser other questions tagged

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