Pregunta

I am learning to create my first website and I've ran into the first problem that I can't solve. I have a navigation bar in which I want to sit nicely within a wrap but the navigation bar sits beneath it and I can't seem to get it right.

Advice would be great.

http://jsfiddle.net/z4pHZ/2/

HTML

<div class="links_container">
    <div class="nav1">
    <ul>
     <li><a href="#" class="noBorder leftedge">Home</a></li>
     <li><a href="#">About</a></li>
     <li><a href="#">Challenges</a></li>
     <li><a href="#">Progress</a></li>
     <li><a href="#" class="rightedge">Forum</a></li>
    </ul>
</div>

CSS

.links_container {
    width: 1000px;
    height: 35px;
    background-color: #33C4AB;
    margin-right: auto;
    margin-left: auto;
    border-bottom-style: double;
    border-bottom-width: 2px;
    border-color: #000000;
    /* [disabled]-webkit-box-sizing: inherit; */
    /* [disabled]-moz-box-sizing: inherit; */
    /* [disabled]box-sizing: inherit; */
    position: absolute;
}

.nav1 {
    float: left;
}
.nav1 ul li {
    list-style-type: none;
    float: left;
    display: block;
}
.nav1 ul li a {
    color: #FFFFFF;
    text-decoration: none;
    background-color: #333333;
    display: inherit;
    height: 35px;
    width: 130px;
    text-align: center;
    line-height: 35px;
    border-left: thin solid #CCCCCC;
}
.noBorder {
    border-left-style: none !important;
}
.nav1 ul li a:hover {
    background-color: #6B6B6B;
    height: 35px;
}
.leftedge {
    border-top-left-radius: 8px;
    border-bottom-left-radius: 8px;
}
.rightedge {
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
}
¿Fue útil?

Solución

Try using

*{
margin:0;
}

and/or

.nav1 ul {
    display: inline;
}

The first code will remove the default browser margin from the webpage, and the second code will display .nav1 ul as an inline element

Also, it's a good idea to think about removing .nav1{float:left;} since it doesn't affect anything, and change the .links_container width to 100% instead of 1000px.

Demo

Otros consejos

You can use display: inline for your ul

.nav1 ul {
    display: inline;
}

Updated Fiddle

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top