Solved

CSS Padding changes width

Posted on 2006-06-14
6
818 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Creating a CSS block that only applies to printing By default, all of your CSS applies to every possible view of your page - whether on screen, printed, landscape, touch-screen, or whatever.  You can, however, add CSS that only applies under certai…
This is a how to build your own CSS3 slideshow and when I say CSS3 I mean just CSS with no javascript in sight! There a few examples online of how to do this but most just show you an example without any explanation, others make it more complicat…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

733 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