473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Css navbar problem!!! Help!!!

Hi, I have created a css navbar with a sprite image, and i'm trying to center it by putting it in a div, inside its parent div, but the navbar sits under the div and wont go inside of the div. Please help me fix this problem, im fairly new to html and css.

**** HTML ****

Expand|Select|Wrap|Line Numbers
  1. <div id="nav">
  2. <div id="navbar">
  3. <ul class="cssmenu">
  4.         <li class="home"><a href="#" class="selected" title="Home"><span class="displace">Home</span></a></li>
  5.         <li class="news"><a href="#" title="News"><span class="displace">News</span></a></li>
  6.         <li class="forum"><a href="#" title="Forum"><span class="displace">Forum</span></a></li>
  7.         <li class="video"><a href="#" title="Video"><span class="displace">Video</span></a></li>
  8.         <li class="support"><a href="#" title="Support"><span class="displace">Support</span></a></li>
  9.         <li class="chat"><a href="#" title="Chat"><span class="displace">Chat</span></a></li>
  10.         <li class="contact"><a href="#" title="Contact"><span class="displace">Contact</span></a></li>
  11. </ul>
  12. </div>
  13. </div>
  14.  
**** CSS ****

Expand|Select|Wrap|Line Numbers
  1. #banner {
  2.     background-color: #777;
  3.     padding: 5px;
  4.     height: 104px;
  5.     width: 905px;
  6.     margin-top: 10px;
  7.     margin-right: auto;
  8.     margin-left: auto;
  9.     border: 2px solid #000;
  10. }
  11. #nav {
  12.     background-color: #777;
  13.     padding: 5px;
  14.     height: 54px;
  15.     width: 905px;
  16.     margin-right: auto;
  17.     margin-left: auto;
  18.     border: 2px solid #000;
  19.     margin-top: 10px;
  20. }
  21. .displace {
  22.     position: absolute;
  23.     left: -5000px;
  24. }
  25.  
  26. /*
  27. *    Setup
  28. */
  29. ul.cssmenu {
  30.     list-style: none;
  31.     padding: 0px;
  32.     }
  33.  
  34. ul.cssmenu li {
  35.     float: left;
  36.     }
  37.  
  38. ul.cssmenu li a {
  39.     display: block;
  40.     width: 90px;
  41.     height: 54px;
  42.     background: url("images/nav.png");
  43.     }
  44.  
  45.     /*
  46. *    Normal Links
  47. */
  48. ul.cssmenu li.home a {
  49.     background-position: 0 0;
  50.     }
  51.  
  52. ul.cssmenu li.news a {
  53.     background-position: -90px 0;
  54.     }
  55.  
  56. ul.cssmenu li.forum a {
  57.     background-position: -180px 0;
  58.     }
  59. ul.cssmenu li.video a {
  60.     background-position: -270px 0;
  61.     }
  62. ul.cssmenu li.support a {
  63.     background-position: -360px 0;
  64.     }
  65. ul.cssmenu li.chat a {
  66.     background-position: -450px 0;
  67.     }
  68. ul.cssmenu li.contact a {
  69.     background-position: -540px 0;
  70.     }
  71. /*
  72. *    Hover Links
  73. */
  74. ul.cssmenu li.home a:hover {
  75.     background-position: 0 -54px;
  76.     }
  77.  
  78. ul.cssmenu li.news a:hover {
  79.     background-position: -90px -54px;
  80.     }
  81.  
  82. ul.cssmenu li.forum a:hover {
  83.     background-position: -180px -54px;
  84.     }
  85. ul.cssmenu li.video a:hover {
  86.     background-position: -270px -54px;
  87.     }
  88. ul.cssmenu li.support a:hover {
  89.     background-position: -360px -54px;
  90.     }
  91. ul.cssmenu li.chat a:hover {
  92.     background-position: -450px -54px;
  93.     }
  94. ul.cssmenu li.contact a:hover {
  95.     background-position: -540px -54px;
  96.     }
  97.  
  98.  
  99. /*
  100. *    Clicked Links
  101. */
  102. ul.cssmenu li.home a:active {
  103.     background-position: 0 -108px;
  104.     }
  105.  
  106. ul.cssmenu li.news a:active {
  107.     background-position: -90px -108px;
  108.     }
  109.  
  110. ul.cssmenu li.forum a:active {
  111.     background-position: -180px -108px;
  112.     }
  113. ul.cssmenu li.video a:active {
  114.     background-position: -270px -108px;
  115.     }
  116. ul.cssmenu li.support a:active {
  117.     background-position: -360px -108px;
  118.     }
  119. ul.cssmenu li.chat a:active {
  120.     background-position: -450px -108px;
  121.     }
  122. ul.cssmenu li.contact a:active {
  123.     background-position: -540px -108px;
  124.     }
  125.  
  126. /*
  127. *    Selected/Active Links
  128. */
  129. ul.cssmenu li.home a.selected {
  130.     background-position: 0 -162px;
  131.     }
  132.  
  133. ul.cssmenu li.news a.selected {
  134.     background-position: -90px -162px;
  135.     }
  136.  
  137. ul.cssmenu li.forum a.selected {
  138.     background-position: -180px -162px;
  139.     }
  140.  
  141. ul.cssmenu li.video a.selected {
  142.     background-position: -270px -162px;
  143.     }
  144. ul.cssmenu li.support a.selected {
  145.     background-position: -360px -162px;
  146.     }
  147. ul.cssmenu li.chat a.selected {
  148.     background-position: -450px -162px;
  149.     }
  150. ul.cssmenu li.contact a.selected {
  151.     background-position: -540px -162px;
  152.     }
  153.  
  154. #navbar {
  155.     width: 630px;
  156.     height: 54px;
  157.     margin-right: auto;
  158.     margin-left: auto;
  159.     }
  160.  
Jul 1 '10 #1
1 1396
TheServant
1,168 Expert 1GB
Welcome to Bytes.
I recommend you getting Mozilla Firefox if you don't have it already and getting the addon "Firebug" which lets you analyse a page to see where containers are, their height, width etc.

Your problem is probably that the <ul> has no height and the <li>'s are being pushed under it, which happens to be out of the <div>. You can fix this in numerous ways, but try and give your <ul> a height and use the css attribute:
Expand|Select|Wrap|Line Numbers
  1. overflow: hidden;
The other way is to float your <ul> which means it will include the floated <li>'s inside. If you do this, you will need to make the granparent div width 100%, and then give the parent div:
Expand|Select|Wrap|Line Numbers
  1. margin: 0 auto;
which will center it.

See how you go with all that ;)
Jul 6 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Holly | last post by:
I'm trying to get this page to look the same in Netscape and IE. I have a box that says 'Upcoming Events' on the lower left of the page. It's supposed to have a gray background, but in NS 4.x it...
15
by: Alfonso Morra | last post by:
Hi, I have some code from an example, that I want to retrofit into my project. The code from the example has the following line: SharedAppenderPtr myAppender( new...
25
by: bruce.james.lee | last post by:
hi i have a problem with integer subtraction in C. printf("%d", c < (a - b)); a is got from a #define and is 0x80000000 and b is got from input and is also 0x80000000. c is ffffffff (-1). Now,...
4
by: Madhu Gopinathan | last post by:
Hi All, I am faced with a horrible hang problem. I have a COM exe server that executes some tasks. The task execution manager is a thread that manages the pool of threads, which is 4 per processor....
1
by: Simon Harvey | last post by:
Hi, I'm hoping someone can help me witht he following problem: I have a fairly simple page that has a sort form and a button for adding the forms details to an arraylist. When the button is...
4
by: Jeff User | last post by:
Hi I tryed to solve this problem over in the framework.asp group, but still am having trouble. Hope someone here can help. using .net 1.1, VS 2003 and C# I have an asp.DataGrid control with a...
3
by: gauravkg via DotNetMonster.com | last post by:
Hi i have a problem I have a product product_name=taj Mahal product_id=111 i and different users will be putting reviews title and review description. this is the following xml file i...
1
by: rxgmoral | last post by:
dll problem,help me:) i create dll project ,the dll is Use MFC in a Static Library i hope exe call ListCtrl class from dll ==================DLL====================...
8
by: Dhananjay | last post by:
hello everyone Do you have any information how to generate a tool using .net which is used to translate the web page contents to html format. Plz reply me asap Thanks in advance Dhananjay
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.