just_user
just_user

Reputation: 12059

Avoid padding in list

I'm working on a menu that expands if the opened page has any children. It looks like this:

http://jsfiddle.net/phacer/qzykv/

Just bellow the inner menu in lighter grey there is a bit of padding from its < li > parent. I was thinking of using line height but in some places the menu item is two lines of text. And I also need to use the dotted border between each item.

Any suggestions of how I can get what I have now but without that padding for a parent that has children?

html:

<nav>
<ul class="menu"><li class="first"><a href="#" title="" >Home</a></li>
<li class="active"><a href="#" title="" >Home</a><ul><li class="first"><a href="#" title="" >Home</a></li>
<li><a href="#" title="" >Home</a></li>
<li class="last"><a href="#" title="" >Home</a></li>
</ul></li>
<li><a href="#" title="" >Home</a></li>
<li><a href="#" title="" >HomeHome HomeHome Home HomeHome </a></li>
<li><a href="#" title="" >Home</a></li>
<li><a href="#" title="" >Home</a></li>
<li><a href="#" title="" >Home</a></li>
<li class="last"><a href="#" title="Contact" >Contact</a></li>
</ul>
</nav>​

CSS:

nav { width: 165px; min-height: 500px; position: relative; display: inline-block; float: left; }
nav ul li { padding: 10px 0 10px 20px; }
nav ul li a { margin-right: 10px; max-width: 125px; }
nav ul li.first { padding-top: 23px; }
nav ul li ul { margin-left: -20px; margin-top: 10px; }
nav ul li ul li { padding-left: 30px; }
nav ul li ul li.first { padding-top: 10px; }
nav ul li ul li ul { margin-left: -30px; margin-top: 10px; }
nav ul li ul li ul li{ padding-left: 40px; }
nav ul li ul li ul li.first { padding-top: 10px; }

nav ul li.active ul li a,
nav ul li.active ul li a:visited,
nav ul li.active ul li.active ul li a,
nav ul li.active ul li.active ul li a:visited       { color: #5c5c5c; }
nav a:hover,
nav ul li.active a                                  { color: #e0001b; }
nav ul li.active ul li.active a,
nav ul li.active ul li.active ul li.active a,
nav ul li.active ul li a:hover,
nav ul li.active ul li.active a:hover  { color: #91298e; }

nav                 { background: #5c5c5c repeat-x left top; }
nav ul li           { border-bottom: 1px dotted #fff; }
nav ul li ul        { background: #d6d6d7; }
nav ul li ul li     { border-bottom: none; border-top: 1px dotted #555; }
nav ul li ul li ul  { background: #ecedee; }

nav { font-size: 12px; list-style-type: none; line-height: 14.5px; text-align: left; }

Upvotes: 3

Views: 127

Answers (2)

Bot
Bot

Reputation: 11855

You need to add nav ul li.active{padding:10px 0 0 10px;} to your css to remove the bottom padding of the active li with a ul

See http://jsfiddle.net/qzykv/5/

Upvotes: 1

Rupali Shinde
Rupali Shinde

Reputation: 333

You have to add following line in your CSS. It will remove padding of parent li who has child.

nav ul li.active{padding:0px;}

Upvotes: 0

Related Questions