amachree tamunoemi
amachree tamunoemi

Reputation: 827

change ul li from horizontal to vertical

I am trying to do a Menu that will appear when Window width is resized to a small resolution. Below is the HTML and CSS are below

<nav>
 <a id="menu-dropdown"><img src="http://localhost/influenza/logo/menu.png" /></a>
 <ul>
    <li><a class="tab-click" href="http://localhost/influenza/index.php">Home</a></li>
    <li><a href="http://localhost/influenza/articles.php">Articles</a></li>
    <li><a href="http://localhost/influenza/webinars.php">Webinars</a></li>
 </ul>
</nav>

CSS:

nav ul
{
    list-style:none;
}
nav li{
    display:inline;
    line-height:1.5px;
}
nav li:not(:first-child) > :only-child,
nav ul > :first-child a{
   text-decoration:none;
   font-size:1.4em !important;
   outline:1px solid blue;
   padding:8px;
   letter-spacing:0.9px;
   margin-left:18px;
}  
nav li:not(:first-child) > :only-child{
   color:blue;
}
nav ul > :first-child a{
  color:white !important;
  background:blue;
}

Output in Horizontal:

Home    Articles    Webinars

How can I bring back the list to Vertical then set "ul" position to absolute and make "nav a" to be visible. The list should display vertically like below

Home
Articles
Webinars

Upvotes: 0

Views: 3247

Answers (1)

John Shang
John Shang

Reputation: 417

nav{
    position:relative;
}
nav ul
{
    position:absolute;
    top:40px; /* this height is same as the menu.png */
    left:0;
    z-index:999;
    list-style:none;
}
nav li{
    list-style:none;
    display:block;
}
nav ul li a{
    display:block;
}
nav li:not(:first-child) > :only-child,
nav ul > :first-child a{
   text-decoration:none;
   font-size:1.4em !important;
   outline:1px solid blue;
   padding:8px;
   letter-spacing:0.9px;
   margin-left:18px;
}  
nav li:not(:first-child) > :only-child{
   color:blue;
}
nav ul > :first-child a{
  color:white !important;
  background:blue;
}
<nav>
 <a id="menu-dropdown"><img src="http://localhost/influenza/logo/menu.png" /></a>
 <ul>
    <li><a class="tab-click" href="http://localhost/influenza/index.php">Home</a></li>
    <li><a href="http://localhost/influenza/articles.php">Articles</a></li>
    <li><a href="http://localhost/influenza/webinars.php">Webinars</a></li>
 </ul>
</nav>

Upvotes: 2

Related Questions