Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm creating a vertical navbar using HTML and vanilla CSS. So I've tried setting the border for each list item individually and it is just limited to  the text. What should I do in a different way?


What I have tried:

HTML
<ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">Settings</a></li>
    <li><a href="#">Logout</a></li>
</ul>




CSS
*, html {
    margin:0;
    padding:0;  
}

ul {
    background: #596275;
    height: 10vh;
}

li {
    display: inline;
    border-right: 3px solid #1e272e;
}

a {
    color: white;
    text-decoration: none;
}
Posted
Updated 30-Jul-19 4:42am
v2

The simplest solution is to change the li to display: inline-block, and set its height to 100%:
CSS
li {
    display: inline-block;
    border-right: 3px solid #1e272e;
    height: 100%;
}
Demo[^]

If you can drop support for older browsers[^], you could use Flexbox[^] instead:
CSS
ul {
    background: #596275;
    height: 10vh;
    display: flex;
    list-style-type: none;
}

li {
    border-right: 3px solid #1e272e;
}
Demo[^]
 
Share this answer
 
Try This.


<!DOCTYPE html>
<html>
<head>
<style>
ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  width: 200px;
  background-color: #f1f1f1;
}
li{
	margin:10px;
	border: 1px solid black;
}
li a {
  display: block;
  color: #000;
  padding: 8px 16px;
  text-decoration: none;
}

/* Change the link color on hover */
li a:hover {
  background-color: #555;
  color: white;
}
</style>
</head>
<body>

<h2>Vertical Navigation Bar</h2>

<ul>
  <li><a href="#home">Home</a></li>
  <li><a href="#news">About</a></li>
  <li><a href="#contact">Setting</a></li>
  <li><a href="#about">Logout</a></li>
</ul>

</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900