Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

visible gap between anchors

I can’t get rid of visible gaps between anchors in my navigation menu. I tried everything with padding, margin and width in nav ul and nav li, but the nav li color is still visible. How can I stretch the red color to the full width of the single anchor?

nav {
    display: flex;
    justify-content: center;
    margin: 0px;
    padding: 0px;
    text-align: center;
    text-decoration: none;
}

nav ul {
    list-style: none;
    padding: 0px;
    margin-top: 0px; 
    background-color: rgb(237, 215, 213);
    border-bottom: 2px solid black; 
    border-left: 2px solid black;   
    border-right: 2px solid black;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
}
  
nav li {
    display: inline-block;
    margin: 0px;
    padding: 10px;
    background-color: red;
    font-size: 20px;
    line-height: 20px;
    border-right: 1px solid black;
}

nav li:last-child {
    border-right: none;
}
<nav>
                <ul>
                    <li><a href="">HOME</a></li>
                    <li><a href="">DESCRIPTION</a></li>
                    <li><a href="">HISTORY</a></li>
                    <li><a href="">LIVE🔴</a></li>
                    <li><a href="">GALLERY</a></li>
                    <li><a href="">CONTACT</a></li>
                </ul>
            </nav>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

A quick fix is to apply display: flex; also to the ul element. Otherwise (as you experienced) the linebreaks in the code cause those spaces.

(You could also remove the linebreaks in the code instead of applying flex, but that’s more work…)

nav {
  display: flex;
  justify-content: center;
  margin: 0px;
  padding: 0px;
  text-align: center;
  text-decoration: none;
}

nav ul {
  display: flex;
  list-style: none;
  padding: 0px;
  margin-top: 0px;
  background-color: rgb(237, 215, 213);
  border-bottom: 2px solid black;
  border-left: 2px solid black;
  border-right: 2px solid black;
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
}

nav li {
  display: inline-block;
  margin: 0px;
  padding: 10px;
  background-color: red;
  font-size: 20px;
  line-height: 20px;
  border-right: 1px solid black;
}

nav li:last-child {
  border-right: none;
}
<nav>
  <ul>
    <li><a href="">HOME</a></li>
    <li><a href="">DESCRIPTION</a></li>
    <li><a href="">HISTORY</a></li>
    <li><a href="">LIVE🔴</a></li>
    <li><a href="">GALLERY</a></li>
    <li><a href="">CONTACT</a></li>
  </ul>
</nav>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading