tags:

views:

51

answers:

4

Although li.textmenu has width: 140px, padding: 5px, and div.textmenu has width: 150px, the one list item i've made so far has a big left margin, and extends beyond the right edge of the div by a good 30px. Could someone explain why?

http://www.briligg.com/frailty.html

css:

    div.textmenu {
        background-color: #3b3b3b;
        float: left;
        width: 150px;
        margin: 30px 10px 0 30px;
        }
li.textmenu {
        background-color: #4a4a4a;
        margin: 0;
        padding: 5px;
        border: none;
        width: 140px;
        list-style: none;
        text-align: right;
        }

html:

<div class="textmenu"> 
<ul> 
<li class="textmenu"><a class="pink" href="http://www.briligg.com/frailty.html#culture"&gt;Stress Causes Addiction</a> 
</li> 
</ul> 
</div> 
+1  A: 

Did you add a zip/uni reset to the top of your css file?

* { margin:0; padding:0; }

( Put that exactly as is at the very top of CSS to override browser default margins/padding ).

Most likely the ul is being given default padding/margin, so this is to counter-act it.

meder
A uni-reset? sorry, that's over my head...
briligg
See instructions.
meder
oh. right. just a sec.
briligg
yep. That worked... Now i'll have to edit the margins and padding of some other stuff that the browser was handling, but i guess that's better coding anyhow...thanks!
briligg
Yes, it makes it much more consistent. Cheers.
meder
+2  A: 

Make sure the ul does not have padding and margin of its own, by resetting it with padding:0;margin:0;

Gaby
Doing it this way would have saved me the need to set margins and padding for everything, but i've gone with the general reset, of putting * {padding: 0; margin: 0;} at the beginning of the css.
briligg
@briligg, see http://meyerweb.com/eric/tools/css/reset/ for a general good reset (*not just margin/padding..*)
Gaby
+2  A: 

The ul has a margin and padding set it on by the browser. You'll want to remove this:

div.textmenu ul {margin:0;padding:0;}

Only the padding affects the width, but you'll probably want to take off the margin too.

+2  A: 

Its like smeridan said. There are for all html elements preset styling properties.

I recommend you to use the reset css by Eric Meyer: http://meyerweb.com/eric/tools/css/reset/

You can include it at the top of your document. After that you have more control about your desired styling.

ChrisBenyamin
That version gets into a lot of stuff i don't think i'll need for a site of this complexity... but it's an interesting resource. I'm going to lookup more 'css reset' stuff.
briligg