html - Navigation menu alignment and active state issue -


i have 2 questions:

  1. how align text middle of box bg color aqua without removing height: 100% want border bottom on active state touch ul's entire height? vertical-align: middle doesn't seem working.
  2. how make sure border-bottom stays highlighted when clicked on link?

ul.nav {    list-style-type: none;    display: flex;    height: 45px;    margin-bottom: 30px;    align-items: center;    background-color: gray;  }    ul.nav .nav-item {    box-sizing: border-box;    margin-right: 20px;    height: 100%;    background-color: aqua;  }    ul.nav .nav-item:active, ul.nav .nav-item:focus {    border-bottom: 3px solid blue;    outline: none;  }    ul.nav .nav-link {    text-decoration: none;  }    ul.nav .nav-link:hover, ul.nav .nav-link:focus, ul.nav .nav-link:active {    text-decoration: none;    outline: none;  }
<ul class="nav">    <li class="nav-item">      <a class="nav-link" href="#">dashboard</a>    </li>    <li class="nav-item">      <a class="nav-link" href="#">account</a>    </li>    <li class="nav-item">      <a class="nav-link" href="#">contact</a>    </li>    <li class="nav-item">      <a class="nav-link" href="#">about</a>    </li>  </ul>

use display: table on li (nav-item) elements , display: table-cell anchor elements within. please see below snippet.

this allow use vertical-align more effectively.

ul.nav {    list-style-type: none;    display: flex;    height: 45px;    margin-bottom: 30px;    align-items: center;    background-color: gray;  }    ul.nav .nav-item {    box-sizing: border-box;    margin-right: 20px;    height: 100%;    background-color: aqua;    display: table;  }    ul.nav > .nav-item > .nav-link:active, ul.nav > .nav-item > .nav-link:focus {    border-bottom: 3px solid blue;    outline: none;  }    ul.nav .nav-link {    text-decoration: none;    display: table-cell;    vertical-align: middle;  }    ul.nav .nav-link:hover, ul.nav .nav-link:focus, ul.nav .nav-link:active {    text-decoration: none;    outline: none;  }
<ul class="nav">    <li class="nav-item">      <a class="nav-link" href="#">dashboard</a>    </li>    <li class="nav-item">      <a class="nav-link" href="#">account</a>    </li>    <li class="nav-item">      <a class="nav-link" href="#">contact</a>    </li>    <li class="nav-item">      <a class="nav-link" href="#">about</a>    </li>  </ul>


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -