ThomasJSmart
Programmer
- Sep 16, 2002
- 634
Hi
I am trying to put together a menu but it is proving difficult.
The situation is as follows:
I have a fixed space for the menu: 960pixels wide.
The number of menus is dynamic
The contents (menu titles) are dynamic
The menus have a graphic left and right, a content section and a pull-down menu on hover.
I am looking for a way to dynamically size the menus so they always fill out the available 960px nicely. Currently I am achieving this with static padding in the css file. But the menu falls apart when anything is changed. A CSS solution would be great but if it can only be done with JS then preferably a jQuery solution. I know it can be done with tables but i would prefer not to have to resort to that
The following is a very simplified (JS and image free) version of the code that is enough to demonstrate this issue and hopefully find a solution. Note that even if you add 1 character to the menu titles the menu 6 wraps to the next line. And if you remove a character (or menu) then there is a big gap on the right.
html:
Suggestions are most appreciated, thank you for your time.
site | blog | iphones |
I am trying to put together a menu but it is proving difficult.
The situation is as follows:
I have a fixed space for the menu: 960pixels wide.
The number of menus is dynamic
The contents (menu titles) are dynamic
The menus have a graphic left and right, a content section and a pull-down menu on hover.
I am looking for a way to dynamically size the menus so they always fill out the available 960px nicely. Currently I am achieving this with static padding in the css file. But the menu falls apart when anything is changed. A CSS solution would be great but if it can only be done with JS then preferably a jQuery solution. I know it can be done with tables but i would prefer not to have to resort to that
The following is a very simplified (JS and image free) version of the code that is enough to demonstrate this issue and hopefully find a solution. Note that even if you add 1 character to the menu titles the menu 6 wraps to the next line. And if you remove a character (or menu) then there is a big gap on the right.
html:
Code:
<html>
<head>
<style>
.menuholder{
height:37px; width:960px;
background:#999;
background-repeat:repeat-x;
clear: both;
}
.menuitem{
position:relative;
float:left; _width: 0px;
height:37px; top:0px;
}
.menuitem:hover{
background-color:#CCC;
}
.menuitemleft, .menuitemright{
width:1px; height:37px;
}
.menuitemright{
background-color:#333;
}
.menuitemleft{
background-color:#fff;
}
.menuitemleft, .menuitemright, .menuitemmid{
float:left;
}
.menuitemmid{
text-align:center;
height:25px;
padding-top:12px;
padding-left:60px;
padding-right:60px;
}
.submenuholder{
background-color:#CCC;
position:absolute; top:36px;
left:1px;right:1px;
display:none;
}
.menuitem:hover .submenuholder{
display:block;
}
</style>
</head>
<body>
<div class="menuholder">
<div class="menuitem">
<div class="menuitemleft"></div>
<div class="menuitemmid">Title 1</div>
<div class="menuitemright"></div>
<div class="submenuholder">
<ul>
<li>Subitem 1-1</li>
<li>Subitem 1-2</li>
<li>Subitem 1-3</li>
</ul>
</div>
</div>
<div class="menuitem">
<div class="menuitemleft"></div>
<div class="menuitemmid">Title 2</div>
<div class="menuitemright"></div>
<div class="submenuholder">
<ul>
<li>Subitem 2-1</li>
<li>Subitem 2-2</li>
<li>Subitem 2-3</li>
</ul>
</div>
</div>
<div class="menuitem">
<div class="menuitemleft"></div>
<div class="menuitemmid">Title 3</div>
<div class="menuitemright"></div>
<div class="submenuholder">
<ul>
<li>Subitem 3-1</li>
<li>Subitem 3-2</li>
<li>Subitem 3-3</li>
</ul>
</div>
</div>
<div class="menuitem">
<div class="menuitemleft"></div>
<div class="menuitemmid">Title 4</div>
<div class="menuitemright"></div>
<div class="submenuholder">
<ul>
<li>Subitem 4-1</li>
<li>Subitem 4-2</li>
<li>Subitem 4-3</li>
</ul>
</div>
</div>
<div class="menuitem">
<div class="menuitemleft"></div>
<div class="menuitemmid">Title 5</div>
<div class="menuitemright"></div>
<div class="submenuholder">
<ul>
<li>Subitem 5-1</li>
<li>Subitem 5-2</li>
<li>Subitem 5-3</li>
</ul>
</div>
</div>
<div class="menuitem">
<div class="menuitemleft"></div>
<div class="menuitemmid">Title 6</div>
<div class="menuitemright"></div>
<div class="submenuholder">
<ul>
<li>Subitem 6-1</li>
<li>Subitem 6-2</li>
<li>Subitem 6-3</li>
</ul>
</div>
</div>
</div>
</body>
</html>
Suggestions are most appreciated, thank you for your time.
site | blog | iphones |