CSS3 vertical flyout menu + transitions not working in FF - html

I've got a vertical flyout navigation. The 2nd level ul block is shown by setting its opacity from 0 to 1 on the parents li:hover;. This works fine in IE and others, but in FF the transition effect doesn't work.
The HTML markup:
<nav>
<ul>
<li>
<a title="" href="">Item</a>
</li>
<li>
<a title="" href="">Item</a>
<ul>
<li>
<a title="" href="">Item</a>
</li>
<li>
<a title="" href="">Item</a>
</li>
<li>
<a title="" href="">Item</a>
</li>
<li>
<a title="" href="">Item</a>
</li>
</ul>
</li>
<li>
<a title="" href="">Item</a>
<ul>
<li>
<a title="" href="">Item</a>
</li>
<li>
<a title="" href="">Item</a>
</li>
</ul>
</li>
<li>
<a title="" href="">Item</a>
</li>
</ul>
</nav>
Part from the CSS:
nav a{
display: block;
}
nav a:hover,
nav li.selected > a{
color: #00fa30;
}
nav li:hover > a,
nav li.selected > a{
color: #00fa30;
}
nav ul{
padding: 0px;
margin: 0px;
list-style-type: none;
}
nav > ul{
border-bottom: 2px solid #006666;
font-size: 16px;
letter-spacing: 1px;
width: 212px;
}
nav > ul > li{
border-top: 2px solid #006666;
padding: 6px 0px;
line-height: 19px;
text-transform: uppercase;
}
nav > ul > li:hover{
position: relative;
z-index: 998;
}
nav > ul > li > ul{
position: absolute;
top: -2px;
left: 212px;
z-index: 999;
opacity: 0;
border: 2px solid #006666;
padding: 0px 6px;
background-color: #eae9e7;
font-size: 16px;
letter-spacing: 1px;
width: 180px;
}
nav > ul > li:hover ul{
opacity: 1;
-webkit-transition: opacity 0.6s ease-in;
-moz-transition: opacity 0.6s ease-in;
-o-transition: opacity 0.6s ease-in;
-ms-transition: opacity 0.6s ease-in;
transition: opacity 0.6s ease-in;
}
nav > ul > li > ul > li{
border-bottom: 2px solid #006666;
padding: 6px 0px;
line-height: 0px;
text-transform: uppercase;
}
nav > ul > li:hover > ul > li{
line-height: 19px;
}
nav > ul > li > ul > li:last-child{
border-bottom: 0px;
}
DEMO

If you remove the :hover from ul > li:hover{ so that it becomes
ul > li {
position: relative;
z-index: 998;
}
then your example provided will work. Sorry if I misinterpret this but here is my understanding. Apparently FireFox cannot properly handle whenever a parent element of a transitioning child has its positioning modified simultaneously. This is a known bug according to this link https://bugzilla.mozilla.org/show_bug.cgi?id=625289.
If you absolutely need to apply frame/position modifying styles on hover to the parent element then you may need another work around via javascript, jQuery, etc, but in your example provided it didn't change anything. For proof here is a working js fiddle: JSFiddle

Related

Dropdown menu not staying when I take the mouse over it

As the title suggests, I've made this dropdown menu and i don't know for what reason when i take my mouse over it or i remove the mouse from the parents element which has the hover effect the dropdown dissapears, i want it to stay so that the user can select.
.sub-menu{
display: none;
}
.sub-menu ul li{
margin: 15px;
width: 120px;
padding: 15px;
}
.navbar-header ul li:hover .sub-menu{
display: block !important;
position:absolute;
background: white;
margin-top: 15px;
margin-left: -15px;
}
.sub-menu ul:hover {
display: block !important;
}
.navbar-header ul li:hover .sub-menu ul{
display: block;
margin: 10px;
-o-transition:.3s ease;
-ms-transition:.3s ease;
-moz-transition:.3s ease;
-webkit-transition:.3s ease;
transition:.3s ease;
outline: none;
}
.sub-menu ul li:hover {
display: block;
background: #f69220;
}
.sub-menu ul li a{
color: black;
}
.navbar-header ul li:hover .sub-menu ul li{
display: block !important;
color: black ;
width: 150px;
padding: 5px;
border-radius: 0;
text-align: center;
}
<div class="navbar-header" style="padding: 0; margin: 0; ">
<ul class="navbar-ul">
<li> <a routerLink="/home"><img src="" class="navbar-logo" alt=""></a>
</li>
<!-- logo -->
<!-- <li><a routerLink="/home">Home</a></li> -->
<!-- <li><a routerLink="/aboutus">About Us</a></li> -->
<li>
<a routerLink="#">About Us</a>
<div class="sub-menu">
<ul>
<li>
Gallery
</li>
<li>
Testimonials
</li>
<li>
Blogs
</li>
</ul>
</div>
</li>
</div>
It's due to margin-top: 15px for submenu. In these 15px you go away from parent LI -> li:hover isn't applied -> submenu is hidden.
Change it for padding, or set margin to first submenu li. Below is a solution with padding-top: 15px.
.navbar-ul > li {background: red; position: relative;}
.sub-menu{
display: none;
}
.sub-menu ul li{
margin: 15px;
width: 120px;
padding: 15px;
}
.navbar-header ul li:hover .sub-menu{
display: block !important;
position:absolute;
background: yellow;
padding-top: 15px; /* padding-top instead of margin-top */
margin-left: -15px;
}
.sub-menu ul:hover {
display: block !important;
}
.navbar-header ul li:hover .sub-menu ul{
display: block;
margin: 10px;
-o-transition:.3s ease;
-ms-transition:.3s ease;
-moz-transition:.3s ease;
-webkit-transition:.3s ease;
transition:.3s ease;
outline: none;
}
.sub-menu ul li:hover {
display: block;
background: #f69220;
}
.sub-menu ul li a{
color: black;
}
.navbar-header ul li:hover .sub-menu ul li{
display: block !important;
color: black ;
width: 150px;
padding: 5px;
border-radius: 0;
text-align: center;
}
<div class="navbar-header" style="padding: 0; margin: 0; ">
<ul class="navbar-ul">
<li> <a routerLink="/home"><img src="" class="navbar-logo" alt=""></a>
</li>
<!-- logo -->
<!-- <li><a routerLink="/home">Home</a></li> -->
<!-- <li><a routerLink="/aboutus">About Us</a></li> -->
<li>
<a routerLink="#">About Us</a>
<div class="sub-menu">
<ul>
<li>
Gallery
</li>
<li>
Testimonials
</li>
<li>
Blogs
</li>
</ul>
</div>
</li>
</div>

How can i make a CSS drop down menu accessible for keyboard navigation?

I saw already some solutions, but i can't figure out how can i put some of these solutions in my code, or some solutions uses something that i can't use in my project.
Let's go to the question:
I need to make an already existing CSS drop-down menu accessible for keyboard navigation. I got some progress in opening the drop-down menu with [Tab] but i can't navigate into the options inside.
Here is my code:
.menu .options-menu-dropdown{
display: inline-block;
font-family: 'OpenSans Bold';
font-size: 16px;
color: #646464;
text-decoration: none;
cursor: pointer;
position: relative;
}
.menu .menu-dropdown{
z-index: -1;
visibility: hidden;
opacity: 0;
position: absolute;
top: 0;
right: 0;
min-width: 180px;
text-align: right;
overflow: hidden;
margin-top: -6px;
margin-right: -6px;
-webkit-transition: all 200ms ease-in-out;
-moz-transition: all 200ms ease-in-out;
-ms-transition: all 200ms ease-in-out;
-o-transition: all 200ms ease-in-out;
transition: all 200ms ease-in-out;
}
.menu .options-menu-dropdown:focus .menu-dropdown,
.menu .options-menu-dropdown:hover .menu-dropdown{
z-index: 100;
visibility: visible;
opacity: 1;
}
.menu .title-dropdown{
background-color: #005e8b;
font-size: 16px;
padding: 8px 6px;
white-space: nowrap;
border-bottom: 1px solid #b4b4b4;
color: #FFF;
}
.menu .menu-dropdown-item{
display: block;
background-color: white;
padding: 12px 32px 12px 12px;
text-decoration: none;
cursor: pointer;
font-size: 16px;
color: #323232;
-webkit-transition: all 200ms ease-in-out;
-moz-transition: all 200ms ease-in-out;
-ms-transition: all 200ms ease-in-out;
-o-transition: all 200ms ease-in-out;
transition: all 200ms ease-in-out;
border-top: #b4b4b4 1px solid;
border-left: #b4b4b4 1px solid;
border-right: #b4b4b4 1px solid;
}
.menu .menu-dropdown-item:last-child{
border-bottom: #b4b4b4 1px solid;
}
.menu .menu-dropdown-item:focus,
.menu .menu-dropdown-item:hover{
background-color: #b4b4b4;
color: #fff;
}
<div class="menu" align="center" >
<div class="options-menu-dropdown" tabindex="0">
<div>Test Menu</div>
<div class="menu-dropdown">
<div class="title-dropdown">Opened Test Menu</div>
Menu Item 1
Menu Item 2
Menu Item 3
</div>
</div>
</div>
code http://codepen.io/WillCodebit/pen/XpaqqJ
Note: I'm trying to avoid any javascript solution, because in this project I need to use GWT for any javascript, it is a pattern that I can't violate.
Thanks in advance.
EDIT
This menu should have a similar behavior than the account menu of Google. And the options inside must be accessible by keyboard too.
I had the exact same question – but did find my answer scattered over different places on the internet which is why I post my solution here. It is a solution that works without JavaScript. The secret lies in these pseudo classes:
li > a:hover + ul,
li > a:focus + ul,
li:focus-within > ul
Full HTML (Header section):
<header>
<nav>
<ul>
<li>
Page 1
<ul>
<li>
Sub page 1
</li>
<li>
Sub page 2
</li>
</ul>
</li>
<li>
Page 2
<ul>
<li>
Sub page 3
</li>
</ul>
</li>
</ul>
</nav>
</header>
Full CSS (without actual styling) – the first level elements are displayed next to each other (display: inline-block;), the second level elements are hidden and appear as soon as the parent element is active:
header ul {
list-style: none;
}
header nav > ul > li {
display: inline-block;
vertical-align: top;
}
header nav > ul > li > ul {
visibility: hidden;
opacity: 0;
}
header nav > ul > li > a:hover + ul,
header nav > ul > li > a:focus + ul,
header nav > ul > li:focus-within > ul {
visibility: visible;
opacity: 1;
}
From Heydon Pickering - Practical ARIA examples:
<nav role="navigation" aria-label="example with dropdowns">
<ul class="with-dropdowns">
<li>Home</li>
<li>
About
<ul aria-hidden="true" aria-label="submenu">
<li>Who we are</li>
<li>What we do</li>
<li>Why</li>
</ul>
</li>
<li>Blog</li>
<li>Contact</li>
</ul>
Thanks to Shannon Youg who tried to help.
I found a solution, but I had to put some Javascript to make it work.
HTML:
<div class="my-menu">
<a id="menuUser" href="javascript:showHideMenu()" class="">
<div>
Test
</div>
</a>
<ul id="menuUserDropdown" class="menu-dropdown">
<li>
<a href="#" class="menu-dropdown-item">
Option 1
</a>
</li>
<li>
<a href="#" class="menu-dropdown-item">
Option 2
</a>
</li>
<li>
<a href="#" class="menu-dropdown-item">
Option 3
</a>
</li>
</ul>
</div>
CSS:
.my-menu a{
display: inline-block;
font-family: 'OpenSans Bold';
font-size: 16px;
color: #646464;
text-decoration: none;
cursor: pointer;
position: relative;
}
.my-menu a div{
padding: 4px 5px 4px 0;
}
.my-menu a.opened div,
.my-menu a:hover div{
background-color: #c9252b;
color: #fff;
}
.my-menu .menu-dropdown.opened{
display: block;
}
.my-menu div{
display: inline-block;
vertical-align: middle;
}
.my-menu .menu-dropdown{
display: none;
margin: 0;
position: absolute;
z-index: 30;
background-color: #FFF;
list-style: none;
padding: 0;
border: 1px solid #b4b4b4;
}
.my-menu .menu-dropdown-item{
display: block;
background-color: white;
padding: 12px;
text-decoration: none;
width: 162px;
cursor: pointer;
font-size: 16px;
color: #323232;
}
.my-menu .menu-dropdown-item:focus,
.my-menu .menu-dropdown-item:hover{
background-color: #b4b4b4;
color: #fff;
}
Javascript, well, I made with GWT, but the logic is simple:
/* Just add or remove the class "opened" from "menuUser" and "menuUserDropdown".
You can put a "blur()" and "mouseLeave()" functions
to close the menu when the user moves away the cursor or
move the focus out of the menu too. */

How Do I give the active menu items a different color - HTML5 CSS

I am trying to add a different color to my active menu items.
I have tried a few different ways but, there must be something I'm missing.
Here is my code:
#menu ul {
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
color: #3d4449;
font-family: "Roboto Slab", serif;
font-family: 400;
letter-spacing: 0.075em;
list-style: none;
margin-bottom: 0;
padding: 0;
text-transform: uppercase;
}
#menu ul a,
#menu ul span {
border-bottom: 0;
color: inherit;
cursor: pointer;
display: block;
font-size: 0.9em;
padding: 0.625em 0;
}
#menu ul a:hover,
#menu ul span:hover {
color: #efa341;
}
#menu ul a.opener,
#menu ul span.opener {
-moz-transition: color 0.2s ease-in-out;
-webkit-transition: color 0.2s ease-in-out;
-ms-transition: color 0.2s ease-in-out;
transition: color 0.2s ease-in-out;
text-decoration: none;
-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
position: relative;
}
#menu ul a.opener:before,
#menu ul span.opener:before {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
text-transform: none !important;
}
#menu ul a.opener:before,
#menu ul span.opener:before {
-moz-transition: color 0.2s ease-in-out, -moz-transform 0.2s ease-in-out;
-webkit-transition: color 0.2s ease-in-out, -webkit-transform 0.2s ease-in-out;
-ms-transition: color 0.2s ease-in-out, -ms-transform 0.2s ease-in-out;
transition: color 0.2s ease-in-out, transform 0.2s ease-in-out;
color: #9fa3a6;
content: '\f078';
position: absolute;
right: 0;
}
#menu ul a.opener:hover:before,
#menu ul span.opener:hover:before {
color: #eda547;
}
#menu ul a.opener.active + ul,
#menu ul span.opener.active + ul {
display: block;
}
#menu ul a.opener.active:before,
#menu ul span.opener.active:before {
-moz-transform: rotate(-180deg);
-webkit-transform: rotate(-180deg);
-ms-transform: rotate(-180deg);
transform: rotate(-180deg);
}
#menu > ul > li {
border-top: solid 1px rgba(210, 215, 217, 0.75);
margin: 0.5em 0 0 0;
padding: 0.5em 0 0 0;
}
#menu > ul > li > ul {
color: #9fa3a6;
display: none;
margin: 0.5em 0 1.5em 0;
padding-left: 1em;
}
#menu > ul > li > ul a,
#menu > ul > li > ul span {
font-size: 0.8em;
}
#menu > ul > li > ul > li {
margin: 0.125em 0 0 0;
padding: 0.125em 0 0 0;
}
#menu > ul > li:first-child {
border-top: 0;
margin-top: 0;
padding-top: 0;
}
<nav id="menu">
<header class="major">
<h2>Menu</h2>
</header>
<ul>
<li>Home
</li>
<li>
<span class="opener">Services</span>
<ul>
<li>Web Development
</li>
<li>Customised Software Development
</li>
<li>E-commerce Solutions
</li>
<li>Software Maintenace
</li>
</ul>
</li>
<li>
<span class="opener">Products</span>
<ul>
<li>Practice Management Application
</li>
<li>Electronic Claims
</li>
<li>Electronic Invoicing
</li>
<li>Debt Recovery
</li>
<li>Automated account collection
</li>
<li>Learner Management System
</li>
</ul>
</li>
<li>Projects
</li>
<li>About Us
</li>
<li>Contact Us
</li>
</ul>
</nav>
you need to apply class like "active" to respective menu and apply css to it
like
#menu ul > li.active > a{
color: red;
}
You need to apply a class to the active menu item.
For example:
#menu ul > li.active > a{
color: red;
background:yellow;
}
Adding the css from above to your code gives you this result:
#menu ul {
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
color: #3d4449;
font-family: "Roboto Slab", serif;
font-family: 400;
letter-spacing: 0.075em;
list-style: none;
margin-bottom: 0;
padding: 0;
text-transform: uppercase;
}
#menu ul a,
#menu ul span {
border-bottom: 0;
color: inherit;
cursor: pointer;
display: block;
font-size: 0.9em;
padding: 0.625em 0;
}
#menu ul a:hover,
#menu ul span:hover {
color: #efa341;
}
#menu ul a.opener,
#menu ul span.opener {
-moz-transition: color 0.2s ease-in-out;
-webkit-transition: color 0.2s ease-in-out;
-ms-transition: color 0.2s ease-in-out;
transition: color 0.2s ease-in-out;
text-decoration: none;
-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
position: relative;
}
#menu ul > li.active > a{
color: red;
}
<nav id="menu">
<header class="major">
<h2>Menu</h2>
</header>
<ul>
<li class="active">Home
</li>
<li>
<span class="opener">Services</span>
<ul>
<li>Web Development
</li>
<li>Customised Software Development
</li>
<li>E-commerce Solutions
</li>
<li>Software Maintenace
</li>
</ul>
</li>
<li>
<span class="opener">Products</span>
<ul>
<li>Practice Management Application
</li>
<li>Electronic Claims
</li>
<li>Electronic Invoicing
</li>
<li>Debt Recovery
</li>
<li>Automated account collection
</li>
<li>Learner Management System
</li>
</ul>
</li>
<li>Projects
</li>
<li>About Us
</li>
<li>Contact Us
</li>
</ul>
</nav>
You can use link:active in CSS like this:
menu ul a:active,
menu ul span:active {
color: #ff0000;
}
It will allow you to adjust whatever you need when the link is clicked and active.
To sum it up:
You want to have active menu items to be styled differently
To achieve this without using JavaScript you have to add a class like "active" (as mentioned above) to your list item tag
You have to do that for each site with its active menu item
Also prefer to change style for list element (like Rahul's answer) rather than applying it to the ulclass like you did in your css.
#menu > li.active > a{ color: #f46e28; }
this will help you definitely.

Auto width for submenu

I can't get this to work, but in my dropdown menu I just simply can't find a way to make the dropdown menu (for example on account) have it scale with the text.
I tried many things, but only so far a static width is working but that is not what I want
<div class="menu-wrap">
<div class="menu">
<ul class="menu-inner">
<li class="home">Home</li>
<li class="account">Mijn Account
<ul>
<li>Mijn website</li>
<li>Profiel</li>
<li>Persoonlijke gegevens</li>
<li>Voorkeuren</li>
<li>Email instellingen</li>
<li>Log uit</li>
</ul>
</li>
<li class="pages">Mijn pagina's
<ul>
<li>Mijn pagina's</li>
<li>Maak een nieuwe pagina</li>
<li>Verander pagina volgorde</li>
</ul>
</li>
<li class="messages">Mijn berichten
<ul>
<li>Alle privè berichten</li>
<li>Verzonden berichten</li>
<li>Verwijderde berichten</li>
<li>Ongelezen berichten</li>
</ul>
</li>
<li class="forum">Forum
<ul>
<li>Nieuwste berichten</li>
<li>Overzicht</li>
<li>Mijn berichten</li>
<li>Top posters</li>
<li>Zoek topic</li>
</ul>
</li>
<li class="search">Zoeken
<ul>
<li>Zoeken</li>
<li>Vandaag jarig</li>
<li>Online leden</li>
<li>Alle leden</li>
<li>Zoek topic</li>
</ul>
</li>
<li class="online">Online (x)
</ul>
</div>
</div>
and the css code:
.menu-wrap{
position: relative;
background-color: rgba(0,0,0,0.8);
height: 30px;
width: 100%;
text-align: center;
}
.menu {
position: relative;
width: 860px;
margin: 0px auto;
height: 30px;
line-height: 30px;
}
.menu ul {
text-align: left;
display: inline;
margin: 0;
padding: 0;
list-style: none;
}
.menu ul li {
font: bold 12px/18px sans-serif;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 5px 22px;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
}
.menu ul li:hover {
background-color: rgba(0,0,0,0.4);
}
.menu ul li a {
color: #fff;
text-decoration: none;
font-size: 14px;
}
.menu ul li ul {
padding: 0;
position: absolute;
top: 28px;
left: 0;
width: auto;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
background-color: rgba(0,0,0,0.4)
}
.menu ul li ul li {
color: #fff;
}
.menu ul li ul li:hover { background-color: rgba(0,0,0,0.4);}
.menu ul li:hover ul {
display:inline-block;
opacity: 1;
visibility: visible;
}
All I want is have the sub menus auto scale in width with the text!
You are going to have to add a white-space property to the .menu ul li ul li rule like so:
.menu ul li ul li {
white-space: nowrap;
}

make submenu wider than main menu

I have this submenu and I would like it so that when the dropdown menu is out it has a width of 100% and covers the whole page. At the moment if I change the width to 100% it just makes it the same width as the main menu.
This is my current HTML:
<header>
<div class="header">
<div class="nav">
<ul>
<li> Services
<ul class="sub"> <a href="services.html#branddesign">
<li><img class="imgcenter" src="images/Brand-Design-Circle-Blue.png" width="100px" />
<br>
Brand Design
</li></a>
<a href="services.html#brandonline">
<li><img class="imgcenter" src="images/Brand-Online-Circle-Blue.png" width="100px" />
<br>
Brand Online
</li></a>
<a href="services.html#brandmarketing">
<li><img class="imgcenter" src="images/Brand-Marketing-Circle-Blue.png" width="100px" />
<br>
Brand Marketing
</li></a>
<a href="services.html#brandmanagement">
<li><img class="imgcenter" src="images/Brand-Management-Circle-Blue.png" width="100px" />
<br>
Brand Management
</li></a>
</ul>
</li>
<li> Clients
</li>
<li> About
</li>
<li> Contact Us
</li>
</ul>
</div>
</div>
</div>
and this CSS:
.header {
position: fixed;
display: block;
float: left;
width: 100%;
height: auto;
background-color: #666;
z-index: 9999;
}
.nav {
position: static;
float: left;
width: 500px;
height: 50px;
margin: 10px 5px;
}
.nav a {
text-decoration: none;
color: #FFFFFF;
}
.nav ul > li:first-child {
padding-bottom: 25px;
}
.nav a:hover {
text-decoration: none;
color: #6db6e5;
}
.nav li {
font-family: "eras_demi_itcregular", Arial, Helvetica;
list-style: none;
float: left;
margin-right: 50px;
}
.nav li:hover a:hover {
padding-bottom: 5px;
border-bottom: 2px solid #6db6e5;
color: #6db6e5;
}
.nav ul li:hover > ul {
height:150px;
}
.nav ul {
list-style: none;
position: absolute;
display: inline-block;
margin-top: 23px;
}
.nav ul ul {
width: 494px;
background: #7d7c7c;
height: 0px;
overflow: hidden;
padding-left:0;
margin-left:0;
font-size: 12px;
text-align: center;
-webkit-transition:all .5s ease-in-out;
-moz-transition:all .5s ease-in-out;
-o-transition:all .5s ease-in-out;
transition:all .5s ease-in-out;
}
.nav ul ul li {
padding: 10px;
margin-left: -1px;
margin-right: 0;
height: 129px;
}
.nav ul ul li:last-child {
}
.nav ul ul li:hover {
background: #666;
}
.nav li li {
height:130px;
-webkit-transition:all .3s ease-in-out;
}
Can anyone please tell me how I can make it so that the submenu can be wider than the main menu?
Try adding this to your CSS:
nav ul ul {
width: 100vw;
left: 0;
}
Fiddle: http://jsfiddle.net/9QE58/1/embedded/result/
That should keep it at 100% of the viewport width no matter what the pixel width is.