September 4, 201214 yr I'm working on a fluid layout with an aim to use on different mobile devices eventually. The layout is working nicely but I can't get the navigation to center. Can anyone tell me how to fix this? Attached are the html and css files. layout.css layout.html
September 4, 201214 yr HI gadgetgirl, The float:left; in your CSS (nav > ul li) is causing this. Modify your CSS by removing the float and adding a text-align:center; to your nav>ul selector. Your CSS should look like this: nav > ul { display:block; color:#f4847f; list-style:none; overflow:hidden; width:87.5%; margin:auto; text-align:center; } nav > ul li { display:inline; margin:10px 5% 0 0; font-size:2.25em; letter-spacing:4px; line-height:1.5em; } I've tested it in Firefox and it works OK. Let me know if it's good. Lyndsey. Edited September 6, 201214 yr by Renaissance-Design Please use the code button or tags to format your code.
September 4, 201214 yr Using text-align:center for alignment of elements is unsemantic. Text-align is for aligning text, not elements. Fix up your nav: width:90%; margin:0 auto; On your UL element, remove the left and right margins and give it a 100% width. Then give your LI elements a 33.3% width, keep them floated, and center align the text so the text is in the middle of the element. Also remove left and right margins. If you change the number of items in your nav, just change the % width of your LI. For example, if you have four items, it will be 25%, 5 items 20% and so on. You should end up with something like the menu on my website, the link is in the signature. Edited September 4, 201214 yr by brightonmike
September 4, 201214 yr Using text-align:center for alignment of elements is unsemantic. Text-align is for aligning text, not elements. Fix up your nav: width:90%; margin:0 auto; On your UL element, remove the left and right margins and give it a 100% width. Then give your LI elements a 33.3% width, keep them floated, and center align the text so the text is in the middle of the element. Also remove left and right margins. If you change the number of items in your nav, just change the % width of your LI. For example, if you have four items, it will be 25%, 5 items 20% and so on. You should end up with something like the menu on my website, the link is in the signature. Thanks for the tip BrightonMike.
September 4, 201214 yr Author @Lyndsey - thanks for the reply, it works nicely. @BrightonMike - thanks for the reply and what you say makes sense. However, I don't want the menu to stretch across the whole of the containing div which is why I originally coded it with a smaller percentage and some margins. Also with your approach when I decrease the window width, the nav elements overlap each other on the same line. In the original version they would jump down to the next line and centre themselves. How would I achieve that same affect using your approach?
September 5, 201214 yr Give this a try <nav> <ul class="topnav"> <li><a href="#portfolioLink">portfolio</a></li> <li><a href="#aboutLink">about</a></li> <li><a href="#" id="emailLink">contact</a></li> </ul> </nav> nav { position:relative; float:right; right:50% } .topnav{ color:#f4847f; list-style:none; position:relative; float:left; left:50% } .topnav li { float:left; margin:10px 30px 0 0; font-size:2.25em; letter-spacing:4px; line-height:1.5em; } #objective { margin:10px auto 0; width:66.666667%; text-align:center; clear:both /*added a clear*/} Edited September 5, 201214 yr by mteam
Create an account or sign in to comment