Keep list elements in the same line when resizing. CSS liquid layout

Antorni picture Antorni · May 3, 2012 · Viewed 8.5k times · Source

I have this menu I found how to made on a tutorial but I have just one trouble. When I resize the page all the layout changes to fit into the new window size but the menu seems to make new lines when the text doesn't fit on the screen. I want that all the menu remains in one line even if the size of the window is too small to show it all. I have tried lots of hacks I've found here but no one seems to work for me. This is the CSS I'm using.

#navcontainer {
margin: auto;
width: 95%;
}
#menu
{
width: 100%;
margin: 0;
padding: 0 0 0 0;
list-style: none;
background: #C2D1DA;
background: -moz-linear-gradient(#DDE7ED, #C2D1DA);
background: -webkit-gradient(linear,left bottom,left top,color-stop(0, #C2D1DA),color-stop(1, #DDE7ED));
background: -webkit-linear-gradient(#DDE7ED, #C2D1DA);
background: -o-linear-gradient(#DDE7ED, #C2D1DA);
background: -ms-linear-gradient(#DDE7ED, #C2D1DA);
background: linear-gradient(#DDE7ED, #C2D1DA);
-moz-border-radius: 50px;
border-radius: 50px;
-moz-box-shadow: 0 2px 1px #9c9c9c;
-webkit-box-shadow: 0 2px 1px #9c9c9c;
box-shadow: 0 2px 1px #9c9c9c;
}
#menu li
{
float: left;
padding: 0 0 10px 0;
position: relative;
line-height: 0;
}
#menu a
{
float: left;
height: 13px;
padding: 0 25px;
color: #1A6B91;
text-transform: uppercase;
font: bold 12px/25px Arial, Helvetica;
text-decoration: none;
text-shadow: 0 0px 1px #004063;
}
#menu li:hover > a
{
color: #333;
}
*html #menu li a:hover /* IE6 */
{
color: #333;
}
#menu li:hover > ul
{
display: block;
}
/*SUB MENU*/
#menu ul
{
list-style: none;
margin: 0;
padding: 0;
display: none;
position: absolute;
top: 23px;
left: 0;
z-index: 99999;
background: #DDE7ED;
background: -moz-linear-gradient(#DDE7ED, #C2D1DA);
background: -webkit-gradient(linear,left bottom,left top,color-stop(0, #C2D1DA),color-stop(1, #DDE7ED));
background: -webkit-linear-gradient(#DDE7ED, #C2D1DA);
background: -o-linear-gradient(#DDE7ED, #C2D1DA);
background: -ms-linear-gradient(#DDE7ED, #C2D1DA);
background: linear-gradient(#DDE7ED, #C2D1DA);
-moz-box-shadow: 0 0 2px rgba(255,255,255,.5);
-webkit-box-shadow: 0 0 2px rgba(255,255,255,.5);
box-shadow: 0 0 2px rgba(255,255,255,.5);
-moz-border-radius: 5px;
border-radius: 5px;
}
#menu ul ul
{
top: 0;
left: 190px;
}
#menu ul li
{
float: none;
margin: 0;
padding: 0;
display: block;
-moz-box-shadow: 0 1px 0 #0A486C, 0 2px 0 #1A6891;
-webkit-box-shadow: 0 1px 0 #0A486C, 0 2px 0 #1A6891;
box-shadow: 0 1px 0 #0A486C, 0 2px 0 #1A6891;*/
}
#menu ul li:last-child
{
-moz-box-shadow: none;
-webkit-box-shadow: none;
box-shadow: none;
}
#menu ul a
{
padding: 10px;
height: 10px;
width: 170px;
height: auto;
line-height: 1;
display: block;
white-space: nowrap;
float: none;
text-transform: none;
}
*html #menu ul a /* IE6 */
{
height: 10px;
width: 170px;
}
*:first-child+html #menu ul a /* IE7 */
{
height: 10px;
width: 170px;
}
#menu ul a:hover
{
background: #0186ba;
background: -moz-linear-gradient(#04acec,  #0186ba);
background: -webkit-gradient(linear, left top, left bottom, from(#04acec), to(#0186ba));
background: -webkit-linear-gradient(#04acec,  #0186ba);
background: -o-linear-gradient(#04acec,  #0186ba);
background: -ms-linear-gradient(#04acec,  #0186ba);
background: linear-gradient(#04acec,  #0186ba);
}
#menu ul li:first-child a
{
-moz-border-radius: 5px 5px 0 0;
border-radius: 5px 5px 0 0;
}
#menu ul li:first-child a:after
{
content: '';
position: absolute;
left: 30px;
top: -8px;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-bottom: 8px solid #DDE7ED;
}
#menu ul ul li:first-child a:after
{
left: -8px;
top: 12px;
width: 0;
height: 0;
border-left: 0; 
border-bottom: 5px solid transparent;
border-top: 5px solid transparent;
border-right: 8px solid #DDE7ED;/*cambiar por gradiente*/
}
#menu ul li:first-child a:hover:after
{
border-bottom-color: #04acec;
}
#menu ul ul li:first-child a:hover:after
{
border-right-color: #04acec; /*cambiar por gradiente*/
border-bottom-color: transparent;   
}
#menu ul li:last-child a
{
-moz-border-radius: 0 0 5px 5px;
border-radius: 0 0 5px 5px;
}
/* Clear floated elements */
#menu:after
{
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}

And the HTML code for the menu structure is here.

<script type="text/javascript">
$(function() {
if ($.browser.msie && $.browser.version.substr(0,1)<7)
{
    $('li').has('ul').mouseover(function(){
        $(this).children('ul').show();
    }).mouseout(function(){
        $(this).children('ul').hide();
    })
}
});
</script>
<div id="navcontainer">
<ul id="menu">
<li><a href="#" onclick="inicio();">Inicio</a></li>
<li><a href="#">ISO 9001</a>
    <ul>
        <li><a href="#">Nueva A.C. o A.P.</a></li>
        <li><a href="#">Tabla A.C. y A.P.</a></li>
    </ul>
</li>
<li><a href="#" onclick="muestras();">Muestras</a>
    <ul>
        <li><a href="#" onclick="muestras();">Solicitud de Muestra</a></li>
        <li><a href="#" onclick="muestrasPendientes();">Muestras Pendientes</a></li>
        <li><a href="#">Muestras Terminadas</a></li>
        <li><a href="#">Garant&iacute;as</a></li>
        <li><a href="#">Cat&aacute;logo de Productos</a></li>
    </ul>
</li>
<li><a href="#" onclick="proyectos();">Proyectos</a>
    <ul>
        <li><a href="#" onclick="proyectos();">Nuevo Proyecto</a></li>
        <li><a href="#" onclick="proyectosVista();">Proyectos</a></li>
        <li><a href="#">Nueva Actividad</a></li>
        <li><a href="#">Actividades Proyectos</a></li>
    </ul>
</li>
<li><a href="#" onclick="tickets();">Tickets</a>
    <ul>
        <li><a href="#" onclick="tickets();">Nuevo Ticket</a></li>
        <li><a href="#" onclick="ticketsAbiertos();">Tickets Abiertos</a></li>
        <li><a href="#" onclick="ticketsTerminados();">Tickets Terminados</a></li>
        <li><a href="#" onclick="ticketsPorTerminar();">Tickets por Terminar</a></li>
    </ul>
</li>
<li><a href="#" onclick="iCalendar();">iCalendar</a></li>
<li><a href="#" onclick="mkt();">MKT</a>
    <ul>
        <li><a href="#" onclick="publicidad();">Enviar Boletin</a></li>
    </ul>
</li>
<li><a href="#">Juntas</a>
    <ul>
        <li><a href="#">Nuevo Compromiso</a></li>
        <li><a href="#">Compromisos Abiertos</a></li>
        <li><a href="#">Compromisos Terminados</a></li>
        <li><a href="#">Todos los Compromisos</a></li>
        <li><a href="#">Nueva Minuta</a></li>
        <li><a href="#">Minutas Anteriores</a></li>
        <li><a href="#">Calendario de Eventos</a></li>
        <li><a href="#">Recordar Compromisos</a></li>
    </ul>
</li>
<li><a href="https://www.estatec.com/webmail" target="_blank">Mail</a></li>
</ul>
</div>
* html #menu{
zoom: 1;
} /* IE6 */
*:first-child+html #menu{
zoom: 1;
} /* IE7 */

This is the menu as I need it http://i.stack.imgur.com/wXLSw.png

This is the problem I got http://i.stack.imgur.com/B01H9.png

I don't care if the menu shows complete or not but I need it on the same line. I hope you can help me

Answer

Christopher Marshall picture Christopher Marshall · May 3, 2012

http://jsfiddle.net/3aSTE/

Set a hard height to the #menu and overflow-y:hidden