简体   繁体   中英

navigation on media cant get 100% width

My navigation cant get a full width on media, I tried every way and cant locate where my mistake is, so I attached you the code, please if any one have an idea how to solve this, and set the width to full width = 100%? The HTML

<nav class="navi" id="target">
    <div class="menu" id="header">

        <li><a class="link-1" href="#">home</a></li>
        <li><a class="link-1" href="#">second</a></li>
        <li><a class="link-1" href="#">third</a></li>
        <div class="logo">
        <li><a href="#"><img alt="Brand" src="logo.png" height="40px" width="60px"></a><li>
        </div>

    </div>
<div class="handle"><p>menu</p></div>
    </nav>

The CSS:

nav {
width:100%;
margin-top: 0;
padding: 10px;
text-align: center;
font-family: arial;
box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.5);
position:fixed;

text-align:right;
z-index:10;


}

nav li{
    display: inline;

}
nav ul{
min-height:20px;

}
.navi{
background: rgba(0,0, 0, 0.5);


}
.navi:hover{
background-color: rgba(0,0,0, 1);
}

.link-1 {
transition: 0.3s ease;
color: #fff;
font-size: 16px;
text-decoration: none;
border-top: 1px solid ;
text-align:right;
padding: 20px 0px;
margin: 0 20px;
font-weight: italic;
letter-spacing:2px;
}
.link-1:hover {
border-top: 2px solid #fff;

text-decoration: none;
color:#fff;

padding: 3px 6px;

}


.logo{
text-align:left;
margin-left:35px;
margin-top:-25px;
}

.menu {display:block;

}
.handle {display:none;}

/*media try*/

@media (max-width: 580px) {

#target{

}
nav {
width:100%;
margin-top: 0;
display:block;
max-height:0;
margin-top:-20px;
padding-top:18px;
padding-right:-20%;

}

nav li{
display:block;
padding:10px;
background:#000;
}
.navi{
background: rgba(0,0, 0, 0.9);
text-align:center;
border:0;
background:#000;
}
.navi:hover{
background-color: rgba(0,0,0, 1);
border:0;

}

.link-1 {
border:0px solid #bbb;
font-size:18px;

}
.link-1:hover {
text-decoration:underline;
border:0px solid #bbb;

}


.logo{
text-align:left;
margin-left:35px;
margin-top:-25px;
    display: none;
}
.menu {display:none;

}
.handle {display:block;
color:#fff;
font-size:40px;
text-decoration:none;
text-align:right;

}
.handle:hover{

}
.handle  p{
color:#fff;
cursor: pointer;
   -webkit-text-stroke: 1px black;
    -webkit-font-smoothing: antialiased;

}


}

I fixed the HTML.

Add box-sizing: border-box; for nav .

ul tag is missing in your html.

Also make sure to remove the default padding and margin for ul .

nav ul{ padding: 0; margin:0;}

To stretch menu to full width of the window, apply the bg colour for nav , Or remove the padding:10px from nav .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM