css - How can I style this HTML5 navigation bar? -


this code navigation:

<div class="wrapper">         <header>             <nav class="nav">                 <ul>                     <li><a href="#">home</a></li>                     <li><a href="#">company</a></li>                     <li><a href="#">markets/solutions</a></li>                     <li><a href="#">products/services</a></li>                     <li><a href="#">businesses</a></li>                     <li><a href="#">investors</a></li>                 </ul>             </nav>             </header>             </div> 
*{     box-sizing:border-box; } body{     margin:0;     padding:0;     font-family:verdana;     font-size:12px; } .wrapper{     margin-left:auto;     margin-right:auto; } nav ul{     background-color: red;  } nav ul li{     display:inline-block;     padding:15px;  } nav ul li a{     text-decoration: none;     color: #ffffff; } nav ul li:first-child:hover{     text-decoration: underline;     background-color:none; } nav ul li:hover{     background-color:#000; } 

demo on jsfiddle

if put width:960px; wrapper, cut margin on both sides. need avoid using text-align:center; nav ul because of happens when window resized. when window shrunk, lists should center aligned; in window of normal size, lists should displayed in left side of navigation bar.

jsfiddle - demo or show [edited]

you use css3 @media queries small screen sizes.

html:

<div class="wrapper">     <header>         <nav class="nav">             <ul>                 <li><a href="#">home</a>                 </li>                 <li><a href="#">company</a>                 </li>                 <li><a href="#">markets/solutions</a>                 </li>                 <li><a href="#">products/services</a>                 </li>                 <li><a href="#">businesses</a>                 </li>                 <li><a href="#">investors</a>                 </li>             </ul>         </nav>     </header> </div> 

css:

* {     box-sizing:border-box; } body {     margin:0;     padding:0;     font-family:verdana;     font-size:12px; } .wrapper {     max-width:100%;     margin-left:auto;     margin-right:auto;     text-align: center; } nav ul {     background-color: red; } nav ul li {     display:inline-block;     padding:15px; } nav ul li {     text-decoration: none;     color: #ffffff; } nav ul li:first-child:hover {     text-decoration: underline;     background-color:none; } nav ul li:hover {     background-color:#000; } @media (max-width: 960px) {     nav {         text-align: left;     } } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

jquery - Keeping Kendo Datepicker in min/max range -