Search code examples
htmlcsslistskeleton-css-boilerplate

How do i stop my list overlapping my header image?


I have a website I'm building, i'm using Skeleton CSS and everything is responsive and works fine.

i have a menu bar (list) in the correct place, but when I resize, it seems to overlap my header image, does anybody know how I can stop this?

Example here: http://www.cosworth-europe.co.uk/test/indextest.html

Please resize your browser down.

HTML:

    <div id="top"><center><img src="images/header.png" style="max-width:100%;"></center></div>
<header id="header" class="site-header" role="banner">
<div id="header-inner" class="container sixteen columns over">
<hgroup class="one-third column alpha">

</hgroup>
    <nav id="main-nav" class="two thirds column omega">
        <ul>
            <li>
                <a href="index.html">Home</a>
            </li>
            <li>
                <a href="about-us.html">About Us</a>
            </li>
            <li>
                <a href="news.html">News</a>
            </li>
            <li>
                <a href="dealers.html">Dealers</a>
            </li>
            <li>
                <a href="products.html">Products</a>
            </li>
            <li>
                <a href="http://www.cosworth-europe.co.uk/shop">Buy Online</a>
            </li>
            <li>
                <a href="contact.html">Contact</a>
            </li>
        </ul>
    </nav>

</div>

</header>

CSS:

#top {background-image: url(../images/header-gradient.gif);
 background-repeat: repeat-x; 
 max-width:100%;
 height:110px;}

#header {margin-top: -5px; margin-bottom: 30px;}
h1 a { text-indent: -9999px; }
#site-title { padding-top: 10px;}

#main-nav { 
    position:absolute;
    right:120px;
    bottom:0px; 
}

#main-nav ul, #main-nav li {display: inline; padding: 7px;}
#main-nav a {text-decoration:none; color: black;}

Solution

  • You should use media queries to deal with how elements are positioned depending on the different sizes. You are using position: absolute for the #main-nav which is fixing the navigation bar in place, regardless of the screen size.

    Example:

    CSS:

    #main-nav {
        position: absolute;
        right: 120px; /* Default */
    }
    
    @media only screen and (max-width: 700px) {
        body {  
            #main-nav {
                position: absolute;
                right: 50px; /* Will apply when the screens width is smaller than 700px */
            }
        }
    }