Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Fixed position Dropdownbox menu

    Dear all,

    I have a problem on this site: http://www.frontmountain.com/royalflowers

    I want a fixed position for the drop down menu.

    Below you see the css code? I have tried several things, but it's not working.It'skeep shifting out of position.
    #nav{
    list-style:none;
    text-decoration: none;
    font-size: 14px;
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    margin-bottom:10px;
    /* Clear floats */
    float:left;
    width: 100%;
    height: 30px;
    margin-left: -30px;
    /* Bring the nav above everything else--uncomment if needed.*/
    position: relative;
    z-index: 5;
    }
    #nav li{
    float:left;
    position: relative;
    text-decoration: none;
    }
    #nav a{
    display:block;
    padding:5px;
    color:#fff;
    background:#5e5838;
    width: 135px;

    }
    #nav a:hover{
    color:#fff;
    background:#322f20;
    }

    /*--- DROPDOWN ---*/
    #nav ul{
    background:#fff; /* Adding a background makes the dropdown work properly in IE7+. Make this as close to your page's background as possible (i.e. white page == white background). */
    background:rgba(255,255,255,0); /* But! Let's make the background fully transparent where we can, we don't actually want to see it if we can help it... */
    list-style:none;
    position: absolute;
    margin-left: -40px;
    left:-9999px; /* Hide off-screen when not needed (this is more accessible than display:none */
    }
    #nav ul li{
    padding-top:1px; /* Introducing a padding between the li and the a give the illusion spaced items */
    float: none;
    }
    #nav ul a{
    white-space:nowrap; /* Stop text wrapping and creating multi-line dropdown items */
    }
    #nav li:hover ul{ /* Display the dropdown on hover */
    left:0; /* Bring back on-screen when needed */
    }
    #nav li:hover a{ /* These create persistent hover states, meaning the top-most link stays 'hovered' even when your cursor has moved down the list. */
    background:#322f20;
    text-decoration: none;
    }
    #nav li:hover ul a{ /* The persistent hover state does however create a global style for links even before they're hovered. Here we undo these effects. */
    text-decoration:none;
    }
    #nav li:hover ul li a:hover{ /* Here we define the most explicit hover states--what happens when you hover each individual link. */
    background:#333;
    }


    Can someone help me?

    Thanks in advance.

    Regards,

    William

  • #2
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,694
    Thanks
    22
    Thanked 1,832 Times in 1,816 Posts
    Hello williamvv,
    There is a lot to look at here. I'll fix a couple things to get you started.

    You're using a lot more absolute and relative positioning than you really need to. You also position each image, then position the div element containing it and re-use id's.

    Those sidebar images can lose their containing divs and be positioned on their own. ul#nav doesn't need to be wrapped in a containing div either. Check out this article on divitis and how to avoid it.

    ...

    You also need to know about the box model.
    See the box model here. The box model says that whatever you put inside an element cannot be larger than that element. margin/padding/border all count when figuring width/height.

    Your #wrapper is 1024px wide but you try to put 1100px wide ul#nav in it.

    ...

    Make these changes to your CSS to get started -
    Code:
    @charset "utf-8";
    /* CSS Document */
    html, body {
      margin: 0;
      background: #fc6;
    }
    #wrapper {
    	width: 1024px;
    	margin-left: auto;
    	margin-right: auto;
    	position: relative;
      background: #0f0;
    	/*float: left;*/
    }
    
    img#sidebarleft {
    	position: absolute;
    	left: -101px;
    	top: 0;
    	width: 100px;
    	height: 700px;
    	float: left;
    }
    
    img#sidebarright {
    	position: absolute;
    	right: -101px;
    	top: 0;
    	width: 100px;
    	height: 700px;
    }
    
    .header {
    	width: 1024px;
    	height: 175px;
    	/*position: relative;*/
    }
    
    .logo {
    	position: absolute;
    	top: 0;
    	left: 10px;
    	width: 175px;
    	height: 175px;
    }
    
    .shadow {
    	position: absolute;
    	left: 181px;
    	top: 498px;
    	width: 1015px;
    	height: 13px;
    }
    
    .boxone {
    	position: absolute
    	left: 181px;
    	top: 510px;
    	width: 480px;
    	height: 150px;
    }
    
    /*#navigation {
    	margin-left: 82px;
    }*/
    
    #nav{
    	width: 1100px;
      padding: 0;
    	list-style:none;
    	font-size: 14px;
    	font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    	/* Clear floats */
    	/* Bring the nav above everything else--uncomment if needed.*/
    	z-index: 5; 
    }
    See the links about validation below. You can learn a lot about coding just by fixing errors the validators find for you.




    ...
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •