Flexible vertical menu - html

I'm working on this vertical menu. I need it to be flexible, so even longer text can be shown (as seen in the middle item). I want to keep the "padding" of the items, but I also want to increase the space between the lines for multi-line items (if I increase line-height, the distance from the edges gets bigger). How can I achieve that without increasing the "padding"? The images I use must have transparent background, so I can't use combination color-image (there is a gradient behind).
<div id="nav-list">
<ul>
<li><span class="button-middle">Button</span><span class="button-bottom"></span></li>
<li><span class="button-middle">Another button</span><span class="button-bottom"></span></li>
<li><span class="button-middle">The longest button in the world, even longer</span><span class="button-bottom"></span></li>
<li><span class="button-middle">Button</span><span class="button-bottom"></span></li>
<li><span class="button-middle">Btn</span><span class="button-bottom"></span></li>
</ul>
</div>
CSS:
* {
border: 0;
margin: 0;
padding: 0;
}
#nav-list {
width: 195px;
}
#nav-list ul {
list-style: none;
}
#nav-list ul li {
display: block;
margin: 5px 2px 0 5px;
font-size: 13px;
}
#nav-list ul li a {
display: block;
background: url('http://i41.tinypic.com/20h4hvp.png') top left no-repeat;
padding-top: 10px;
line-height: 10px;
color: #000000;
text-decoration: none;
}
#nav-list ul li a .button-middle {
width: 183px;
background: #b6b6b6;
padding-left: 5px;
display: block;
}
#nav-list ul li a .button-bottom {
width: 188px;
height: 10px;
background: url('http://i39.tinypic.com/2mrd343.png') top left no-repeat;
display: block;
}
Note: I can't use CSS3 because of its weak browser support.

I think the best you can do is add something like:
span.button-middle {
line-height: 1.2;
}
You could also decrease the line-height of the top and bottom of the button to compensate for the bigger middle section:
span.button-bottom {
line-height: 0.8;
}

Well... after hours of struggle I managed to solve it. I had to use different images, add one more span and use some relative positioning.
http://jsfiddle.net/uNCsp/
<div id="nav-list">
<ul>
<li><span class="button-top"><span class="button-middle">Button</span></span><span class="button-bottom"></span></li>
<li><span class="button-top"><span class="button-middle">Another button</span></span><span class="button-bottom"></span></li>
<li><span class="button-top"><span class="button-middle">Even longer button button button button</span></span><span class="button-bottom"></span></li>
<li><span class="button-top"><span class="button-middle">Button</span></span><span class="button-bottom"></span></li>
<li><span class="button-top"><span class="button-middle">Button</span></span><span class="button-bottom"></span></li>
</ul>
</div>
CSS:
#nav-list {
width: 195px;
}
#nav-list ul {
list-style: none;
}
#nav-list ul li {
display: block;
margin: 5px 2px 0 5px;
font-size: 13px;
}
#nav-list ul li a {
display: block;
color: #000000;
text-decoration: none;
}
#nav-list ul li a .button-top {
background: url('http://i43.tinypic.com/r0urzp.png') top left no-repeat;
display: block;
}
#nav-list ul li a .button-middle {
position: relative;
top: 6px;
background: transparent;
padding: 0 0 0 5px;
display: block; /* IE7 bug */
line-height: 16px;
padding-bottom: 3px;
}
#nav-list ul li a .button-bottom {
width: 188px;
height: 10px;
background: url('http://i44.tinypic.com/15fqbti.png') top left no-repeat;
display: block;
}
#nav-list ul li a:hover .button-top {
background: url('http://i39.tinypic.com/334qfsz.png') top left no-repeat;
}
#nav-list ul li a:hover .button-bottom {
background: url('http://i41.tinypic.com/2ewinti.png') top left no-repeat;
}
There is a problem in IE7 (marked in the code), but I believe I'll solve that quickly.

Related

Trouble centering a CSS list menu within a div

I'm hitting a wall with my relatively basic knowledge of CSS. I've put together a menu with the intention of centering it within its div. For whatever reason, all attempts at centering it with CSS (margin 0 & set width for the menu's ID) have failed, so I've resigned to changing the width of the div to just barely fit all of the menu options and centered that on the page.
However, this has caused it to be displayed incorrectly in a couple browsers (mainly Safari).
Heres the CSS:
#primary_nav_wrap {
display: block;
}
#primary_nav_wrap ul {
list-style: none;
text-align: center;
position: relative;
float: left;
margin: 0;
padding: 0
}
#primary_nav_wrap ul a {
display: block;
margin: 0 auto;
color: #8a7e70;
text-decoration: none;
font-size: 13.9pt;
padding: 0 10px;
letter-spacing: 2px;
font-family: Engravers;
}
#primary_nav_wrap ul li {
display: inline;
position: relative;
float: left;
padding: 0
}
#primary_nav_wrap ul ul {
display: none;
width: 204px;
position: absolute;
top: 100%;
left: 50%;
padding-top: 10px;
padding-bottom: 10px;
background: rgba(0, 0, 0, 0.92);
margin-left: -100px
}
#primary_nav_wrap ul ul li {
float: none;
width: 204px
}
#primary_nav_wrap ul ul a {
font-family: Eavesregular;
font-size: 12pt;
letter-spacing: .5px !important;
line-height: 120%;
padding: 5px 5px
}
#primary_nav_wrap ul ul ul {
top: 0;
left: 100%
}
#primary_nav_wrap ul li:hover>ul {
display: block
}
a:hover,
a:active,
li:hover,
li:active,
ul:hover,
ul:active {
color: #bfb3a0 !important;
}
and my HTML
<div id="primary_nav_wrap">
<ul>
<li><span style="color:#fffdf2;">philosophy</span></li>
<li>collection
<ul>
<li>Shades of Black</li>
<li>L' Amour du Sauvage</li>
<li>Dark Phoenix</li>
<li>Buy the Collections</li>
</ul>
</li>
<li>fashionshow
<ul>
<li>Phoenix New York<br />Grand Central Station</li>
</ul>
</li>
<li>press
</li>
<li>blog</li>
<li><a class="lastcontact" href="/wild/contact">contact</a></li>
</ul>
</div>
and here's the website:
https://christianpersi.co/wild/
Thank you for any and all help!
Have a look at using flex to position your elements.
By default flex will render your items in a row, you can set justify-content: center; to align everything centre with a margin for spacing. You can have center on the parent of the menu, and inside the ul for the menu justify-content: space-between; to space them evenly, but as #Bhargav pointed out, your issue is probably down the number of characters you have in your menu breaking the layout with a limited width to sit in.

Horizontal list li not taking up the whole height

<ul class="nav">
<li><i class="icon-home"></i></li>
<li>Blog</li>
<li>Elements</li>
<li>Contact us</li>
</ul>
.nav {
line-height: 70px;
margin: 0;
padding: 0;
border: 0;
}
.nav li {
list-style-image: none;
list-style-type: none;
margin-left: 0;
white-space: nowrap;
display: inline;
float: left;
padding-left: 4px;
padding-right: 4px;
}
.active {
background: pink;
}
.icon-home {
background: url(http://i.stack.imgur.com/MNme0.png) no-repeat;
width: 16px;
height: 14px;
display:block;
}
body {
background: gray;
}
How do I make the background of .active take up the whole height of li and center the icon? If you check the demo it doesn't respect the line-height of the li.
Demo: http://codepen.io/anon/pen/ulEGw
You could set .icon-home to display: inline-block;, which will center it vertically with the rest of the text.
You can also keep your line-height this way.
Assuming you want to keep your line-height: 70px on .nav, put height: 70px; on .icon-home.

Make li to cover ul completely without fixed width of li

I have a horizontal menu navigation.
The code is:
<div class="menu-holder">
<ul class="menu">
<li>
Home
</li>
<li>
Profile
</li>
<li>
Billing
<ul class="submenu">
<li>New</li>
<li>Find</li>
</ul>
</li>
<li>
Workspaces
</li>
<li>
Manage Leaves
</li>
<li>
Blogs
</li>
<li>
News
</li>
<li>
Search
</li>
<li>
Albums
</li>
</ul>
</div>
The CSS:
ul.menu {
list-style: none;
padding: 0 20px;
margin: 0;
float: left;
width: 960px;
background: #222;
font-size: 1.2em;
-moz-border-radius: 20px;
-webkit-border-radius: 20px;
-khtml-border-radius: 20px;
border-radius: 10px;
behavior: url(CSS3PIE);
}
ul.menu li {
float: left;
margin: 0;
padding: 0 15px 0 0;
position: relative;
}
ul.menu li a{
padding: 10px 5px;
color: #fff;
display: block;
text-decoration: none;
float: left;
}
ul.menu li a:hover{
background: url(Images/topnav_hover.gif) no-repeat center top;
}
ul.menu li span {
width: 17px;
height: 35px;
float: left;
background: url(Images/subnav_btn.gif) no-repeat center top;
}
ul.menu li span.subhover {background-position: center bottom; cursor: pointer;}
ul.menu li ul.submenu {
list-style: none;
position: absolute;
left: 0; top: 44px;
background: #333;
margin: 0; padding: 0;
display: none;
float: left;
width: 170px;
border-radius: 5px;
-webkit-border-radius: 5px;
border: 1px solid #111;
behavior: url(CSS3PIE);
}
ul.menu li ul.submenu li{
margin: 0; padding: 0;
border-top: 1px solid #252525;
border-bottom: 1px solid #444;
clear: both;
width: 170px;
}
html ul.menu li ul.submenu li a {
float: left;
width: 145px;
background: #333 url(Images/dropdown_linkbg.gif) no-repeat 10px center;
padding-left: 20px;
}
html ul.menu li ul.submenu li a:hover {
background: #222 url(Images/dropdown_linkbg.gif) no-repeat 10px center;
}
There is also jQuery has been used to create this navigation.
Now I want to make the li completely cover ui. But without applying fixed width to li. Because there is also another menu item(not in picture) which will be visible depending on the role of the logged in user.
Is it possible?
I believe the best way to solve this is to use display: table/table-cell instead of float: left. Here's a fiddle: http://jsfiddle.net/nk7yY/
Basically, what you'd change in your code is:
ul.menu {
display: table;
width: 100%; /* Tables are not 100% width like block elements */
/* Everything you already had except float: left; which I don't really get why you have to begin with */
}
ul.menu li {
display: table-cell;
/* Everything you already had except float: left; */
}
ul.menu li a {
/* Just remove the float here as well */
}
Edit: This won't work in old IE though, but you can keep the float for them (with a *float hack for example).
Are you saying you have 9 ul.menu li elements and there will some times be a 10th? and that you want all 9 (or 10) together to fill the width of the ul.menu?
or are you talking about the ul.submenu?
Just saying "make the li completely cover ui" also sounds like you want a single <li> to cover the entire width of the navigation ui (assuming its your <ul> and not some other parts of your UI.
Is this what your trying to do? or do you just want all 9 or 10 <li> items to fill the space of the <ul> ?
If so you should probably put a class on <ul class="menu"> which changes depending on the role of the logged in user so that you can adjust the styling accordingly.
Supply a bit more information on what your attempting to do and what browsers your wanting to support i.e. for CSS3.

How to add nav icon images using max-width property in CSS

So I'm working on a personal project and I'd like to add icon images to the left of each nav menu item. 3 things are bugging me;
I can't get the icons to sit left of the menu items
I can't get the icons to resize using the max-width property
I also need the icons to remain in place on hovering.
http://www.toastcafebar.com/nav/
<nav role="navigation">
<ul>
<a class="cinema" href="cinema.html">Movies</a>
<a class="tv" href="tv.html">T.V Shows</a>
</ul>
</nav>
...and the CSS
nav[role="navigation"] ul {
display: inline-block;
text-align: center;
margin-top: 50px;
}
nav[role="navigation"] ul a {
width: auto;
margin: 0 50px;
font-size: 2em;
padding: .5em;
width: auto;
}
a.cinema {
display: block;
background: url(images/pop.png) no-repeat left center;
padding-left: 75px;
}
.tv {
display: block;
background: url(images/tv.png) no-repeat;
padding-left: 100px;
}
nav a:link, a:visited {
font-weight: normal;
text-decoration: none;
outline: none;
color: #000;
}
nav a:hover {
color: #999;
background: #666;
-moz-border-radius: .5em;
border-radius: .55em;
padding: .25em;
}
Any suggestions?
Cheers in advance
Your markup is a bit funky. If you have a <ul> element, you should only have <li> children.
HTML:
<nav role="navigation">
<ul>
<li><a class="cinema" href="cinema.html">Movies</a></li>
<li><a class="tv" href="tv.html">T.V Shows</a></li>
</ul>
</nav>
CSS:
nav[role="navigation"] ul {
display: inline-block;
text-align: center;
margin-top: 50px; }
nav[role="navigation"] ul li {
font-size: 2em;
margin: 0 50px;
display: inline-block; }
nav[role="navigation"] ul a {
background-position: .5em 50%;
background-repeat: no-repeat;
text-decoration: none;
outline: none;
color: #000;
padding: .5em .5em .5em 75px;
display: block; }
nav[role="navigation"] ul li a.cinema { background-image: url(http://www.toastcafebar.com/nav/images/pop.png); }
nav[role="navigation"] ul li a.tv { background-image: url(http://www.toastcafebar.com/nav/images/tv.png); }
nav[role="navigation"] ul li a:hover {
color: #999;
background-color: #666;
-moz-border-radius: .5em;
border-radius: .55em; }
Preview: http://jsfiddle.net/Wexcode/bGNgr/
What you need to do is the <a> tags to display:block;, and have the icon as a background image, aligned left with no-repeat. Then make sure you apply padding-left on the <a>so the text doesn't overlap the image. For example:
a.cinema {
display: block;
background: url(/path/to/img.png) no-repeat left center;
padding-left: 90px;
}
Use that as a base! No need for max-width...
To get the icon to autoresize to fit the "button size" you could use the CSS3 property "background-size". But I think the best way is to resize the icons manually, some browsers does not support CSS3 properties correct yet.
http://www.css3.info/preview/background-size/
Use both classes as follows, you may reach to answer,
nav a:hover {
-moz-border-radius: 0.5em 0.5em 0.5em 0.5em;
background: url(images/pop.png) no-repeat scroll left center #666666;
color: #999999;
}
a.cinema {
display: block;
background: url(/path/to/img.png) no-repeat left center;
text-indent: 35px;
}

HTML+css dropdown centering

I have this menu:
#navbar {
text-align: center;
margin: auto;
padding: 0;
height: 1em;
}
#navbar li {
list-style: none;
float:left; }
#navbar li a:hover{
background-color: #CCC;
}
#navbar li a {
border: 1px solid #000;
display: block;
margin-right: 18px;
margin-left: 18px;
padding: 3px 8px;
background-color: #FFF;
color: #000;
text-decoration: none; }
#navbar li ul {
display: none;
width: 10em; /* Width to help Opera out */
}
#navbar li:hover ul {
display: block;
position: absolute;
margin: 0;
padding: 0; }
#navbar li:hover li {
float: none; }
#navbar li:hover li a {
background-color: #FFF;
border-bottom: 1px solid #000;
color: #000; }
#navbar li li a:hover {
background-color: #CCC; }
<ul id="navbar">
<li>Start</li>
<li>Vad?</li>
<li>Kom igång!</li>
<li>Läringsartikler<ul>
<li>Subitem One</li>
<li>Second Subitem</li>
<li>Numero Tres</li></ul>
</li>
<li>Läringsfilmer<ul>
<li>Subitem One</li>
<li>Second Subitem</li>
<li>Numero Tres</li></ul>
</li>
</ul>
as you can see in navbar { i tried to use text-align: center or margin:auto but it still wont center the whole menu..
why?
when i change the navbar li to float center instead of float left then it make the whole menu stupid big
You need to specify a width on your navbar ul.
#navbar {
text-align: center;
margin: auto;
padding: 0;
height: 1em;
width: 400px;
}
There is NO center value for 'float' style attribute
-- Oops dint see that comment
As mentioned, there is no Float:center. In order to center using margin-left and margin-right auto, you either need to set a width (as mentioned above) or change it to display:block.
If you don't want to set a width or can't, there's a CSS hack called Shrink Wrapping that is easy to setup.