Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CSS Padding changes width

Posted on 2006-06-14
6
Medium Priority
?
836 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 375 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
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…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
Suggested Courses

636 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