I'm currently working on a vertical menu with the capability of having submenus. My aim is to include a vertical line using CSS pseudo-element ::before
along with border
.
The challenge I'm encountering is that the CSS is applying to the entire menu instead of the specific submenu I intended.
I suspect the issue may be related to the use of position: absolute;
, however, removing it results in the border not appearing at all.
You can view the code below and observe the problem in this JsFiddle.
<ul id="test-ul">
<li><a>one</a></li>
<li>
<a>two</a>
<ul class="submenu">
<li><a>sub one</a></li>
<li><a>sub two</a></li>
<li><a>sub three</a></li>
</ul>
</li>
<li><a>three</a></li>
<li><a>four</a></li>
<li><a>five</a></li>
</ul>
<style>
/* reset defaults */
ul { list-style: none; }
/* apply style to menu */
#test-ul {
background-color: #eee;
border-color: #ccc;
position: absolute;
}
/* style links */
#test-ul > li a {
color: #2b7dbc;
border-top-color: #e4e4e4;
background-color: #fff;
display: block;
padding: 7px 0 9px 20px;
border-top-width: 1px;
border-top-style: dotted;
}
/* utilize CSS3 technique to display a vertical border on the left of each submenu item */
#test-ul > li > ul::before {
content: "";
display: block;
position: absolute;
z-index: 1;
left: 18px;
top: 0;
bottom: 0;
border: 1px dotted;
border-width: 0 0 0 1px;
}
</style>