views:

168

answers:

2

Hi All,

Trying to learn a bit of CSS and I want a horizontal navbar and I am using ul and li to build it. I would like all the 'buttons' to have the same width, is that possible with just CSS?

Thanks

+1  A: 

Yup,

ul li
{
    display: block;
    float: left;
    width: 100px;
}
ul
{
    padding: 0px;
    list-style-type: none;
}

Something like this. (Not tested);

Ikke
I think the OP wants the buttons width to be inherited by the largest button; not sure if he wants a fixed width or not.
Michael G
I want them all to be the same width and it can be fixed. I tried the width property but I could not get it to work.
willcodejavaforfood
+2  A: 

Not exactly sure what you mean by same width. You just set it with pixels on the link? What are your constraints? do you know the list width? or the link width?

<style type="text/css">
    .menu { margin:0px auto; padding:0px; list-style-type:none; }
    .menu li { margin:0px auto; padding:0px; float:left; }
    .menu li a { display:block; width:200px; }
</style>


<ul class="menu">
    <li><a href="#section1">Section1</a></li>
    <li><a href="#section1">Section1</a></li>
    <li><a href="#section1">Section1</a></li>
</ul>
bendewey