?
Solved

CSS Padding changes width

Posted on 2006-06-14
6
Medium Priority
?
831 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

777 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