Difficulty creating CSS menu with multiple columns - css

I've read through some similar threads on this site and found some helpful tips, but I'm still having difficulty getting columns to work correctly in my CSS drop down menu. The test site is here: http://iphonebuy-host1.gaiahost.net/index.html
In part I'm using ideas from method 4 in this article - http://alistapart.com/article/multicolumnlists - however this is for XHTML and I'm using HTML, maybe that's causing my issue?
The main thing is the list items in the second column don't stick to the bottom of the header. According to the referenced article, setting a negative margin on .reset is supposed to bring the entire second column up where I want it, but only the header (which has .reset applied to it) is moving up.
I should say that you probably have to view my menu in Firefox to see what I'm talking about - so far it's even more messed up in Safari and I haven't even tried IE or Chrome.
CSS
/** top navigation menu **/
.topnav {
list-style: none;
background-color: #FFF;
font: 1.313em arial, sans-serif;
color: #0071BC;
margin: -1.8em 0 1.2em 25em;
text-align: center;
}
.topnav li {
position: relative;
display: inline;
padding: 0 .5em 0 .5em;
border: none;
}
.topnav a {
display: inline-block;
}
/** for drop-down menu **/
.topnav li ol {
background: #fff;
list-style: none;
position: absolute;
width: 15.5em;
font: .8em arial, sans-serif;
padding: 0 1em .5em .5em;
margin-top: -.1em;
left: -9999px;
z-index: 200;
-webkit-border-radius: 0 0 .5em .5em;
-moz-border-radius: 0 0 .5em .5em;
border-radius: 0 0 .5em .5em;
-webkit-box-shadow: 0 3px 2px 1px #ccc;
-moz-box-shadow: 0 3px 2px 1px #ccc;
box-shadow: 0 3px 2px 1px #ccc;
}
.topnav li li h1 {
font: bold 1.2em arial, sans-serif;
white-space: nowrap;
margin: .5em 0 .5em 0;
}
.topnav li li h2 {
font: 1em arial, sans-serif;
white-space: nowrap;
}
.topnav li li a {
white-space: nowrap;
display: block;
}
.topnav li: hover ol {
left: 0;
margin-left: -.9em;
}
.topnav li: hover a {
color: #99CCCC;
}
.topnav li: hover ol a {
color: #0071BC;
}
.topnav li: hover ol a: hover {
color: #99CCCC;
}
.topnav li li.column1 {
margin-left: 0em;
width: 6.8em;
float: left;
line-height: 1.5em;
}
.topnav li li.column2 {
margin-left: 10em;
width: 4em;
float: left;
line-height: 1.5em;
}
.topnav li li.reset {
margin-top: -10.8em;
}
HTML
<div class="topnav">
<ol>
<li>Home</li>
<li>Get Quote
<ol>
<li class="column1"><h1>Select phone:</h1></li>
<li class="column1"><h2>CDMA</h2></li>
<li class="column1">3GS 8GB</li>
<li class="column1">3GS 16GB</li>
<li class="column1">4 8GB</li>
<li class="column1">4 16GB</li>
<li class="column1">4S 16GB</li>
<li class="column1">4S 32GB</li>
<li class="column2 reset"><h2>AT&T GSM</h2></li>
<li class="column2">3GS 8GB</li>
<li class="column2">3GS 16GB</li>
<li class="column2">4 8GB</li>
<li class="column2">4 16GB</li>
<li class="column2">4S 16GB</li>
<li class="column2">4S 32GB</li>
</ol>
</li>
<li>About</li>
</ol>
</div>

The code in the question floats the list items. The method 4 approach that it's based on doesn't. That one change prevents the approach from having the chance to work as intended.
In a case like this, it's best to either stay entirely consistent with the approach, or go in an completely different direction and do not imitate it at all. Getting caught in the middle -- inconsistently following the approach -- is likely to cause the most trouble.
Split the HTML into bite-sized chunks
You'll have a far easier time styling this if you change the HTML. Instead of putting everything into a single list and splitting the list up into 2 columns, try splitting the HTML into 2 separate lists.
It may require adding a few wrapper divs as well. Something like the following:
<div class="topnav">
<ul>
<li>Home</li>
<li>Get Quote
<div class="dropdown">
<h1>Select phone:</h1>
<div class="columns clearfix"> <!-- add a reliable clearfix -->
<div class="column1"> <!-- floated left -->
<h2>CDMA</h2>
<ul>
<li>3GS 8GB</li>
<li>3GS 16GB</li>
...
</ul>
</div>
<div class="column2"> <!-- floated left -->
<h2>AT&T GSM</h2>
<ul>
<li>3GS 8GB</li>
<li>3GS 16GB</li>
...
</ul>
</div>
</div>
</div>
</li>
<li>About</li>
</ul>
</div>
Splitting the related parts of the dropdown into separate HTML elements gives you more flexibility with styling it.
And semantically, HTML of this sort is much better, because the h1 and h2 tags aren't being treated as if they're the same type of content as the specific models of phone. That helps with SEO and accessibility.

Use The following CSS
.topnav {
list-style:none;
background-color:#FFF;
font:1.313em arial, sans-serif;
color:#0071BC;
margin:-1.8em 0 1.2em 25em;
text-align:center;
}
.topnav li {
position:relative;
display:inline;
padding:0 .5em 0 .5em;
border:none;
}
.topnav a {
display:inline-block;
}
.topnav li ol {
background:#fff;
list-style:none;
position:absolute;
width:15.5em;
font:.8em arial, sans-serif;
padding:0 1em .5em .5em;
margin-top:-.1em;
left:-9999px;
z-index:200;
-moz-border-radius:0 0 .5em .5em;
-webkit-border-radius:0 0 .5em .5em;
border-radius:0 0 .5em .5em;
-moz-box-shadow: 0 3px 2px 1px #ccc;
-webkit-box-shadow: 0 3px 2px 1px #ccc;
box-shadow: 0 3px 2px 1px #ccc;
}
.topnav li li {
}
.topnav li li h1 {
font:bold 1.2em arial, sans-serif;
white-space:nowrap;
margin:.5em 0 .5em 0;
}
.topnav li li h2 {
font:1em arial, sans-serif;
white-space:nowrap;
}
.topnav li li a {
white-space:nowrap;
display:block;
}
.topnav li:hover ol {
left:0;
}
.topnav li:hover a {
color:#99CCCC;
}
.topnav li:hover ol a {
color:#0071BC;
}
.topnav li:hover ol a:hover {
color:#99CCCC;
}
.topnav li li.column1 {
margin-left: 0em;
width:6.8em;
float:left;
line-height:1.5em;
}
.topnav li li.column2 {
/*margin-left:10em;*/
width:4em;
float:left;
line-height:1.5em;
}
.topnav li li.reset {
margin-top:-10.8em;
}
And The HTML
<div class="topnav">
<ol>
<li>Home</li>
<li>Get Quote
<ol>
<li class="column1"><h1>Select phone:</h1></li>
<div style="width:130px;height:auto;float:left">
<li class="column1"><h2>CDMA</h2></li>
<li class="column1">3GS 8GB</li>
<li class="column1">3GS 16GB</li>
<li class="column1">4 8GB</li>
<li class="column1">4 16GB</li>
<li class="column1">4S 16GB</li>
<li class="column1">4S 32GB</li>
</div>
<div style="width:130px;height:auto;float:left">
<li class="column2"><h2>AT&T GSM</h2></li>
<li class="column2">3GS 8GB</li>
<li class="column2">3GS 16GB</li>
<li class="column2">4 8GB</li>
<li class="column2">4 16GB</li>
<li class="column2">4S 16GB</li>
<li class="column2">4S 32GB</li>
</div>
</ol>
</li>
<li>About</li>
</ol>
</div>
What I did over here is, put column1 inside a division and column 2 on a different division. Hope this will solve your problem. Thank you.

Related

How can I make this menus dropdown items show vertical?

I made this horizontal menu, and everything was nice and good, until I realized that I can't make the submenus appear vertical, can someone help me?
Here is the menu code:
<div id="nav_custom">
<div id="nav_custom_wrapper"></div>
<ul>
<li>NEW ARRIVALS
</li>
<li>
SEQUIN DRESSES
<ul id="nav_custom_sub">
<li>AVAILABLE</li>
<li>EXAMPLES SOLD</li>
</ul>
</li><li>
BOHO DRESSES
<ul id="nav_custom_sub">
<li>AVAILABLE</li>
<li>EXAMPLES SOLD</li>
</ul>
</li><li>
MOD DRESSES
<ul id="nav_custom_sub">
<li>AVAILABLE</li>
<li>EXAMPLES SOLD</li>
</ul>
</li><li>
PSYCHEDELIC DRESSES
<ul id="nav_custom_sub">
<li>AVAILABLE</li>
<li>EXAMPLES SOLD</li>
</ul>
</li><li>
COATS & JACKETS
<ul id="nav_custom_sub">
<li>AVAILABLE</li>
<li>EXAMPLES SOLD</li>
</ul>
<li>
KIMONOS
<ul id="nav_custom_sub">
<li>AVAILABLE</li>
<li>EXAMPLES SOLD</li>
</ul>
</li>
</ul>
</div>
Here is the css that I have used:
#nav_custom {
text-decoration: none;
font-family: 'Source Sans Pro', sans-serif;
font-size: 14px;
font-style: normal;
font-variant: normal;
font-weight: 400;
line-height: 49px;
color: #000;
display: block;
padding: 10px;
width: 960px;
margin-left: -35px;
margin-right: auto;
text-align: center;
width: auto;
}
#nav_custom_wrapper {
width: 960px;
margin-left: auto;
margin-right: auto;
text-align: center;
}
#nav_custom ul{
list-style-type: none;
padding: 0;
margin: 0;
position: relative;
}
#nav_custom ul li{
display: inline-block;
}
#nav_custom ul li:hover{
color: #000;
text-decoration: none;
}
#nav_custom ul li a,visited{
color: #BA7145;
padding: 15px;
text-decoration: none;
}
#nav_custom ul li a:hover{
color: #000;
text-decoration: none;
}
#nav_custom ul li:hover ul{
display: block;
}
#nav_custom ul ul{
display: none;
position: absolute;
margin-top: -25px;
margin-left: -50px;
text-align: center;
color: #4f4f4f;
}
Remove the inline-block on the #nav_custom ul li
See fiddle for working example: http://jsfiddle.net/Tv77g/
Inline-block works similarly to floats, which is why they were stacking left to right next to each other instead of one on top of each other.
I didn't go through to adjust your children. I don't know how the menu is supposed to display. Most likely the children (#nav_custom ul ul) would have the margins adjusted. You can remove text-align:center; on #nav_custom to make the menu completely left aligned.
To set this only on children, add
#nav_custom_sub li {
display: block !important;
}
This will override the inline-block for only the children (in the dropdown). You will have to adjust the margins to make them appear correctly.

How do I keep nested children (li) inline for my footer navigation?

I have a simple question. I'm trying to display the elements for "about" "general" and "social-buttons" classes within a nested unordered list. I want these to appear horizontal and inline with each other. I want them to be side by side basically, not vertical. If you can help me figure out which selector I need to add the 'display:inline' block, that would be much useful.
<div class="footer-container">
<div id="footer_menu">
<div id="footer-copy">
<li class="about-blurb">
<h3>Viral DNA</h3>
<ul>
<li>
<p>Virael Marketing is the leading digital marketing blog for the social web. We are a one-stop hub to help you learn from your viral marketing campaigns, offer tips & tricks, and build the best digital marketing teams.</p>
</li>
</ul>
<li class="General">
<h3>General</h3>
<ul>
<li><a class="button" href="#">Media</a></li>
<li><a class="button" href="#">Resources</a></li>
<li><a class="button" href="#">Blog</a></li>
<li><a class="button" href="#">Store</a></li>
<li><a class="button" href="#">Contact</a></li>
</ul>
<li class="social-icons">
<h3>Follow Virael</h3>
<ul>
<li>
<!--social media buttons go here-->
</li>
</ul>
</ul>
</div>
</div>
The CSS:
.footer-container {
font-family: MyriadPro-Regular, 'Myriad Pro Regular', MyriadPro,'MyriadPro', Arial, sans-serif;
float: left;
text-align: left;
width: 828px;
text-transform: capitalize;
background-color: #4169E1;
color: #FFF;
position: relative;
bottom: 0;
left: 269px;
border-top: 10px solid #B0C4DE;
overflow: hidden;
z-index=-1000;
}
.footer-container h3 {
text-align:justify;
}
#footer_menu {
font-family: MyriadPro-Regular, 'Myriad Pro Regular', MyriadPro,'MyriadPro', Arial, sans-serif;
list-style-type:none;
z-index=-1000;
}
#footer_menu ul {
margin: 0px 30px;
padding: 10px 30px;
list-style-type:none;
text-decoration:none;
display:inline;
z-index=-1000;
}
#footer_menu ul li {
margin: 0 0;
padding: 5px 0;
z-index=-100;
display:block;
color: white;
clear:both;
}
#footer_menu .about-blurb ul li {
width: 200px;
height: auto;
text-align:justify;
}
Replace your css with mine. Live example here
#footer_menu ul {
/* margin: 0px 30px; */
padding: 10px 30px;
list-style-type: none;
text-decoration: none;
display: inline;
}
#footer_menu ul li {
margin: 0 0;
padding: 5px 0;
display: inline-block;
color: white;
clear: both;
}
Remove margins from the ul and add inline-block to li

Horizontal navigation can't align to right

I know this has been discussed here before - as I've read through a lot of questions about the same thing. And have tried the solutions, but I just can't seem to make this stupid nav right align (needing li blocks to align to the right). Can someone please point out my mistake - thank you.
http://jsfiddle.net/gstricklind/vP38J/4/
CSS
ul#menu-main-top {
float: right;
}
.nav-bar > li {
border: 1px solid #333;
display: block;
float: left;
line-height: 38px;
margin: 0;
padding: 0;
position: relative;
}
ul#menu-main-top li a {
color: #222222 !important;
}
.top-nav > li > a {
color: #E6E6E6 !important;
}
.nav-bar > li > a:first-child {
margin: 0 0 0 10px;
padding: 0 0 0 30px;
}
.nav-bar > li > a:first-child {
display: block;
font-size: 14px;
padding: 0 20px;
position: relative;
text-decoration: initial;
}
​HTML
<div class="eight columns">
<ul id="menu-main-top" class="top-nav nav-bar hide-for-small">
<li id="menu-item-58">
Home
</li>
<li id="menu-item-94">
Calendar
</li>
<li id="menu-item-59">
Meanings
</li>
<li id="menu-item-77">
About Us
</li>
<li id="menu-item-67">
Contact Us
</li>
<li id="menu-item-343" class="active">
My Account
</li>
<li class="logout">
Logout
</li>
</ul>
</div>
Is this what you were trying to do?
http://jsfiddle.net/vP38J/5/
Relevent changed code:
.nav-bar > li {
border:1px solid #333;
display:block;
float: right;
line-height:38px;
margin:0;
padding:0;
position:relative;
}
Also, if you are looking to have the order remain the same, just reverse the order of the list in HTML.

UL Dropdown Menu Problems

I have two problems with my dropdown menu, one involving links, the other involving IE7 issues. Code follows after questions, and in both instances, I'm trying to avoid javascript (a key part of the project)
I am successfully highlighting the text of the link when I hover, including some pixels above, below and left & right. However, the only part of the highlight that is clickable (i.e. where I can access a hyperlink) is where the text is, and I want to be able to have the entire highlight, padding and text, to be clickable. I've done it before, but I'm confused with the current code on how to fix it. Can anybody help me out?
Using the same dropdown, everything is working fine, except in IE7. Some IE7 users complained that once they highlighted the menu item and the dropdown occurs, they only get down to about the 2nd item before the dropdown disappears, and it does it for every dropdown. I know it's an issue with IE7, but I need to get a work around for it. Any help at all?
My CSS code:
ul { list-style: none; }
p { margin: 8px 0; }
ul.dropdown { list-style-type:none;height:24px; top:2px; padding:0px 0px 0px 0px;;margin:0px 0px 0 1px;vertical-align:bottom; color:#000000; position: relative; }
ul.dropdown a:hover { color: #000; }
ul.dropdown a:active { color: #ffa500; }
ul.dropdown li { float: left; position:relative; vertical-align:middle; background-position:0 -40px; padding: 2px 4px 5px 2px; margin-right:6px;}
ul.dropdown li a { display: block; padding: 0px 0px; color: #222; text-decoration:none; vertical-align:middle; width:100%;}
ul.dropdown li:last-child a { border-right: none; }
ul.dropdown li.hover,
ul.dropdown li:hover { background: #F3D673; color: black; position: relative; }
ul.dropdown li.hover a { color: black; }
ul.dropdown ul { width: 152px; visibility: hidden; position: absolute; top: 100%; left: -40px; z-index:60;}
ul.dropdown ul li { font-weight: normal; background: #ECEAD8; color: #000; width:100%;/*border-bottom: 1px solid #ccc;*/ float: none; }
ul.dropdown ul li.nohover { color: black; background: #ECEAD8; position:relative; }
ul.dropdown ul li a { border-right: none; width: 100%; display: inline-block; min-height:1.4em;}
ul.dropdown ul ul { left:72.7%;top: 0px; width:158px; z-index:50; display:inline-block;}
ul.dropdown li:hover > ul { visibility: visible; display:block; }
#arrowRight { float:right; margin-top:-11px;}
a.moreItems {background: url(/images/menu/arrow_r.gif) no-repeat right;}
Here is the HTML Code:
<!DOCTYPE HTML>
<html>
<head>
<title></title>
<link rel=stylesheet type="text/css" href="menustylesheet.css">
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="25" class="topmenu" bgcolor="##ECEAD8" nowrap>
<ul class="dropdown">
<li><b>Item 1</b> <img src="/images/menu/arrow_d.gif" border="0" height="7" width="7">
<ul>
<li><a class="moreItems" href="">Item 1-1</a>
<ul>
<li>Item 1-1-1</li>
</ul>
</li>
<li><a class="moreItems" href="">Item 1-2</a>
<ul>
<li>Item 1-2-1</li>
</ul>
</li>
<li>Item 1-3 <div style="vertical-align:middle;"><img src="/images/menu/arrow_r.gif" id="arrowRight" border="0"></div>
<ul>
<li>Item 1-3-1</li>
<li>Item 1-3-2</li>
</ul>
</li>
<li>Item 1-4</li>
<li>Item 1-5</li>
</ul>
</li>
</ul>
</td>
</tr>
<tr><td bgcolor="##c0c0c0" style="height:1px;"></td></tr>
</table>
</body>
</html>
I apologize if this has been answered before, but I hope someone can pinpoint where in the code I need to change or modify to make it work.
I have an answer to your first problem. When doing this kind of menu. I stay as far away from padding as I can. I find it easier just to use margins, but for starters lets look at a page I built for you:
http://www.albatrossfonts.com/stack/ulbuttons.html
I'll explain this code below.
Here is my HTML:
<div id="wrapper">
<ul class="dropdown">
<li>Button 1</li>
<li>Button 1</li>
<li>Button 1</li>
</ul>
</div>
And the CSS:
.dropdown
{
width: 200px;
display:block;
margin: 200px auto 0 auto;
list-style-type: none;
padding: 0;
}
.dropdown li
{
width: 200px;
height: 44px;
display: block;
float: left;
margin: 1px 0 0 0;
list-style-type: none;
padding: 0;
}
.dropdown li a:link, .dropdown li a:visited
{
width: 200px;
height: 44px;
display: block;
float: left;
margin: 0;
color: #ffffff;
background-color: #666666;
text-decoration: none;
text-indent: 12px;
line-height: 44px;
}
.dropdown li a:hover
{
background-color: #333333;
}
Notice that I declared a:link, instead of just a. I also declared a:visited since I want the visited state to be the same as the original state.
In the .dropdown entry, I simply defined a width for the list (ul) and made it display properly.
In the .dropdown li entry, I set the width and height of each list item, removed bullets, and set the display and float to make them display as a box. No padding. Just a box.
In the .dropdown li a:link, .dropdown li a:visited entry, what we are essentially doing is "filling" our list item boxes with a link, and it just so happens that we can define a link as a box as well. So I set the dimensions of the link to the exact same size as our li's (this is what makes the entire box clickable). Then set the display and float, and a background color, as well as a text color, or simply "color."
In order to get your text in the center, you should not use vertical-align. Use line-height, and set it to the same height as your li element. This will center your text in the box vertically.
To control where your text appears horizontally, set a text-indent property, use text-align. In this example, I used text-indent.
Finally, we define our a:hover state. It's important to remember that the only things you truly need to define here are any properties that actually change. In this case, the background color.
If you wanted to ad a state for the mouse down event, you could do something like:
.dropdown li a:active
{
background-color: #000000;
text-indent: 20px;
}
/////////// Edit////////////
Here's how you would use a single css styles for multiple menus or child menus.
html for 2 separate ul's:
<ul class="dropdown">
<li>Button 1</li>
<li>Button 1</li>
<li>Button 1</li>
</ul>
<ul class="dropdown">
<li>Button 1</li>
<li>Button 1</li>
<li>Button 1</li>
</ul>
CSS: (stays the same, because you assign both of them to the class "dropdown."
.dropdown
{
width: 200px;
display:block;
margin: 200px auto 0 auto;
list-style-type: none;
padding: 0;
}
.dropdown li
{
width: 200px;
height: 44px;
display: block;
float: left;
margin: 1px 0 0 0;
list-style-type: none;
padding: 0;
}
.dropdown li a:link, .dropdown li a:visited
{
width: 200px;
height: 44px;
display: block;
float: left;
margin: 0;
color: #ffffff;
background-color: #666666;
text-decoration: none;
text-indent: 12px;
line-height: 44px;
}
.dropdown li a:hover
{
background-color: #333333;
}
If you want to apply your styles for a child ul, like this:
<ul class="dropdown">
<li>Button 1
<ul>
<li><a href="#">subButton 1</li>
<li><a href="#">subButton 2</li>
<li><a href="#">subButton 3</li>
</ul>
</li>
<li>Button 1</li>
<li>Button 1</li>
</ul>
You simply append your styles to include the child ul and child ui li, as follows; where .dropdown actually represents your first ul. So .dropdown(ul) --> li (list item in "dropdown" unordered list) --> ul (ul inside dropdown li) --> li (li inside dropdown ul li ul)
Sorry if that sounds confusing, but in other words, if you didn't assign a class to your parent ul at all, it would be ul li ul li to access a list item inside a child list.
.dropdown, dropdown li ul
{
width: 200px;
display:block;
margin: 200px auto 0 auto;
list-style-type: none;
padding: 0;
}
.dropdown li, .dropdown li ul li
{
width: 200px;
height: 44px;
display: block;
float: left;
margin: 1px 0 0 0;
list-style-type: none;
padding: 0;
}
.dropdown li a:link, .dropdown li a:visited, .dropdown li ul li a:link, .dropdown li ul li a:visited
{
width: 200px;
height: 44px;
display: block;
float: left;
margin: 0;
color: #ffffff;
background-color: #666666;
text-decoration: none;
text-indent: 12px;
line-height: 44px;
}
http://www.webcredible.co.uk/user-friendly-resources/css/internet-explorer.shtml
^This has helped me on many occasions to find work-arounds for IE.

Is it possible to make a pure CSS Tree diagram?

I've made an attempt here. However, it has two problems:
IE
Last element of a list being a sublist
Is there a better way of doing this?
You didn't really go into detail on what your criteria are, but from what you have said, I'd suggest taking a look at SlickMap CSS.
Update: Got it! I just remembered where I'd seen what you're looking for:
jsTree is a jQuery plugin which creates a tree widget with the kind of styling you want and uses <ul> internally to represent it.
Try the code below, it's pure CSS and no JS/jQuery (which IMO is way more compatible), works by manipulating borders and spacing.
Works on FF/Chrome & IE. Enjoy :-)
.parent a,
li {
font-size: 22px;
color: #000;
font-family: "Source Sans Pro", sans-serif;
}
.child a,
li {
font-size: 18px;
color: #000;
}
.subchild a,
li {
font-size: 18px;
color: #888888;
}
.s2child a,
li {
font-size: 16px;
color: #ccc;
}
.tree,
.tree ul {
list-style-type: none;
margin-left: 0 0 0 10px;
padding: 0;
position: relative;
overflow: hidden;
}
.tree li {
margin: 0 0 0 15px;
padding: 0 12px 0 20px;
position: relative;
}
.tree li::before,
.tree li::after {
content: '';
position: absolute;
left: 0;
}
/* horizontal line on inner list items */
.tree li::before {
border-top: 2px solid #000;
top: 14px;
width: 15px;
height: 0;
}
/* vertical line on list items */
.tree li:after {
border-left: 2px solid #000;
height: 100%;
width: 0px;
top: -5px;
}
/* lower line on list items from the first level because they don't have parents */
.tree > li::after {
top: 15px;
}
/* hide line from the last of the first level list items */
.tree > li:last-child::after {
display: none;
}
/* hide line from before the Home or starting page or first element */
.tree > li:first-child::before {
display: none;
}
.tree ul:last-child li:last-child:after {
height: 20px;
}
.tree a:hover {
color: red;
font-weight: 500;
text-shadow: 1px 2px 2px #F3F3F3;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Pure CSS Tree</title>
<link href="tree.css" rel="stylesheet" type="text/css">
</head>
<body>
<ul class="tree">
<li class="parent">Grand Parent
<ul>
<li class="child">Parent
</li>
<li class="child">Parent
<ul>
<li class="subchild">Child
<ul>
<li class="s2child">Grand Child
</li>
<li class="s2child">Grand Child
</li>
<li class="s2child">Grand Child
</li>
<li class="s2child">Grand Child
</li>
<li class="last s2child">Grand Child
</li>
</ul>
</li>
<li class="subchild">Child
<ul>
<li class="s2child">Grand Child
</li>
<li class="s2child">Grand Child
</li>
</ul>
</li>
</ul>
</li>
<li class="child">Parent
</li>
</ul>
</li>
</ul>
</body>
</html>

Resources