0
votes

Alignement de la barre de navigation

    Je dois aligner la barre au milieu de la barre de navigation verticalement. J'ai défini align-items: center for bar mais il aligne uniquement le bouton de connexion. Comme vous pouvez le voir, il est légèrement au-dessus de la position médiane.

    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <div class="container" >
                <nav class="d-flex flex-row">
                    <h1 class="sling"><a href="index.html">Sling</a></h1>
                    <ul>
                        <li><a href="#">Home</a></li>
                        <li><a href="#">Features</a></li>
                        <li><a href="#">Pricing</a></li>
                        <li><a href="#">Testimonial</a></li>
                        <li><a href="#">Download</a></li>
                        <li><a href="#">News</a></li>
                        <li><a href="#">Contact us</a></li>
                    </ul>
                    <button type="button" class="signin">Sign in</button>
                </nav>
            </div>
    nav a{
    color:white;
    }
    nav{
        justify-content: space-between;
        align-items: center;
        background-color: brown;
    
    }
    nav ul{
        list-style: none;
        padding: 0;
        display: flex;
        align-items: center;
        background-color: black;
    
    }
    nav ul li a{
        padding: 1rem 0;
        margin: 0 0.5rem;
        position: relative;
        font-size: 14px;
        font-weight: bold;
    }
    .container{
      background-color: green;
    }

    correctement.


    0 commentaires

    3 Réponses :


    2
    votes

    Vous devez remettre à zéro la marge inférieure de nav ul . La marge existe en raison des styles de navigateur par défaut.

    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <div class="container">
      <nav class="d-flex flex-row">
        <h1 class="sling"><a href="index.html">Sling</a></h1>
        <ul>
          <li><a href="#">Home</a></li>
          <li><a href="#">Features</a></li>
          <li><a href="#">Pricing</a></li>
          <li><a href="#">Testimonial</a></li>
          <li><a href="#">Download</a></li>
          <li><a href="#">News</a></li>
          <li><a href="#">Contact us</a></li>
        </ul>
        <button type="button" class="signin">Sign in</button>
      </nav>
    </div>
    nav a {
      color: white;
    }
    
    nav {
      justify-content: space-between;
      align-items: center;
      background-color: brown;
    }
    
    nav ul {
      list-style: none;
      padding: 0;
      margin-bottom: 0; /* <-- + Added */
      display: flex;
      align-items: center;
      background-color: black;
    }
    
    nav ul li a {
      padding: 1rem 0;
      margin: 0 0.5rem;
      position: relative;
      font-size: 14px;
      font-weight: bold;
    }
    
    .container {
      background-color: green;
    }


    0 commentaires

    2
    votes

    Utilisez mb-0 sur l'UL pour effacer la marge inférieure.

        <nav class="d-flex flex-row align-items-center">
            <h1 class="sling"><a href="index.html">Sling</a></h1>
            <ul class="mb-0">
                <li><a href="#">Home</a></li>
                <li><a href="#">Features</a></li>
                <li><a href="#">Pricing</a></li>
                <li><a href="#">Testimonial</a></li>
                <li><a href="#">Download</a></li>
                <li><a href="#">News</a></li>
                <li><a href="#">Contact us</a></li>
            </ul>
            <button type="button" class="signin">Sign in</button>
        </nav>
    

    https://www.codeply.com/go/Fa33cYUN52


    1 commentaires

    Oui merci!



    0
    votes

    D'autres disent tous d'effacer la marge inférieure. Que diriez-vous de align-items: baseline; au lieu de center:

    nav {
        justify-content: space-between;
        align-items: baseline;
        background-color: brown;
    }
    

    https://jsfiddle.net/davidliang2008/3nzgecrt/4/

     entrez la description de l'image ici

    p>


    0 commentaires