Solved

CSS Padding changes width

Posted on 2006-06-14
6
810 Views
Last Modified: 2007-12-19
Using MSIE.  I have a nested UL tree.

<ul>
  <li><a href="#">Products</a></li>  
        <ul>
        <li><a href="#">Financial Software</a></li>
              <ul>
              <li>Simple Start</li>
                    <ul>
                    <li>Overview  </li>
                  </ul>
             
              <li>Pro 2006</li>
            </ul>
        </ul>
</ul>

My CSS is:
ul {  margin: 0px; padding: 0px;width: 181px;font: 10px verdana; font: 11px arial}
li { list-style: none; }
li a {width: 181px;;float:left; text-decoration:none; color: #000000}

ul a{ background: #A3A3A3;  font: bold 12px arial; padding: 10px 0px 10px 0px }
ul ul a {background: #D0D0D0; font: 11px arial;  padding: 5px 0px 5px 0px }

DOCTYPE:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

QUESTION:
When I change the padding on the nested A to indent it (Padding-left: 10px) then it widens the entire area past 181px.  How can I avoid this?
0
Comment
Question by:Kokoglen
  • 4
  • 2
6 Comments
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 16906919
First, your code is not valid.  UL element can only contain LI elements, not other UL elements.
You need to have your nested UL inside a LI.
Something like this:

<ul>
  <li><a href="#">Products</a>  
       <ul>
       <li><a href="#">Financial Software</a>
            <ul>
            <li>Simple Start
                 <ul>
                 <li>Overview  </li>
               </ul></li>
           
            <li>Pro 2006</li>
          </ul></li>
       </ul></li>
</ul>
0
 
LVL 4

Author Comment

by:Kokoglen
ID: 16907669
Ok, I fixed the validity.  It still is doing the same thing.  When I add padding, the entire width increases.
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 16909000
Total width = width + padding + borders.

If you have this:
li a { width: 181px; padding-left: 10px; }
The total width will be 191px.

If you want the total width to be 181px, just reduce the width:
li a { width: 171px; padding-left: 10px; }
0
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
LVL 4

Author Comment

by:Kokoglen
ID: 16909028
That doesn't help me because I am making a tree structure and can't give each level different widths.  Text-indent gives me the padding I need, but is that supported across browsers?
0
 
LVL 30

Accepted Solution

by:
GrandSchtroumpf earned 125 total points
ID: 16909526
if you want your list to be 181px, just don't specify any width on the <a>.
and if you need the <a>'s to fill the entire width, don't float them and use: a { display: block;}
specifying too many width is a common mistake.
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 16909534
check out this site for examples:
http://css.maxdesign.com.au/listamatic2/index.htm
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
stop navigation from wrapping 7 78
Centered Image 2 27
URGENT - Wordpress site missing  theme 9 41
How to make footer stick to bottom 9 29
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question