html - Center an inline list in div example not working -
i creating liquid layout example shown below using exact html example shown in book html , css jon duckett-
* { font-family: arial, verdana, sans-serif; color: #665544; text-align: center; } body { width: 90%; margin: 0 auto; min-width: 400px; } #content { overflow: auto; } #nav, #feature, #footer { margin: 1%; } .column1, .column2, .column3 { width: 31.3%; float: left; margin: 1%; } .column3 { margin-right: 0%; /* no effect anyway float left */ } li { display: inline; padding: 0.5em; } #nav, #footer { background-color: #efefef; padding: 0.5em 0; } #feature, .article { height: 10em; margin-bottom: 1em; background-color: #efefef; }
<!doctype html> <html> <head> <title>liquid layout</title> </head> <body> <div id="header"> <h1>logo</h1> <div id="nav"> <ul> <li id="home"><a href="">home</a></li> <li><a href="">products</a></li> <li><a href="">services</a></li> <li><a href="">about</a></li> <li id="contact"><a href="">contact</a></li> </ul> </div> </div> <div id="content"> <div id="feature"> <p>feature</p> </div> <div class="article column1"> <p>column one</p> </div> <div class="article column2"> <p>column two</p> </div> <div class="article column3"> <p>column three</p> </div> </div> <div id="footer"> <p>© copyright 2011</p> </div> </body> </html>
when viewed in full screen, ul
list isn't in centre of div. thought, centre div, should 2 things
- define width less container.
- set margin
0 auto
so, set ul
element width 70% , margin 0 auto
. result in snippet below produces strange result.
* { font-family: arial, verdana, sans-serif; color: #665544; text-align: center; } body { width: 90%; margin: 0 auto; min-width: 400px; } #content { overflow: auto; } #nav, #feature, #footer { margin: 1%; } .column1, .column2, .column3 { width: 31.3%; float: left; margin: 1%; } .column3 { margin-right: 0%; /* no effect anyway float left */ } ul { width: 70%; margin: auto; } li { display: inline; padding: 0.5em; } #nav, #footer { background-color: #efefef; padding: 0.5em 0; } #feature, .article { height: 10em; margin-bottom: 1em; background-color: #efefef; }
<!doctype html> <html> <head> <title>liquid layout</title> </head> <body> <div id="header"> <h1>logo</h1> <div id="nav"> <ul> <li id="home"><a href="">home</a></li> <li><a href="">products</a></li> <li><a href="">services</a></li> <li><a href="">about</a></li> <li id="contact"><a href="">contact</a></li> </ul> </div> </div> <div id="content"> <div id="feature"> <p>feature</p> </div> <div class="article column1"> <p>column one</p> </div> <div class="article column2"> <p>column two</p> </div> <div class="article column3"> <p>column three</p> </div> </div> <div id="footer"> <p>© copyright 2011</p> </div> </body> </html>
all of padding lost, , list still not centered. doing wrong?
you need add padding-left:0px;
ul. style default web automatically provides -- add padding ul elements.
here's screenshot computer. chrome browser gives ul's default styling below.
Comments
Post a Comment