Click here to Skip to main content
15,910,234 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello. I am trying to create a horizontal fixed menu with four list items. I'd like to place my logo in the center of the menu, so there're two list items on each side of it. I have created a space between the 2nd and 3rd list item, so there's room for the logo, but I can't get the logo to stay in the middle of the page whilst being on top of the navigation, when it has the position:fixed. (The point is, that the entire menu and logo should stay in the same place when scrolling)

HTML
<!doctype html>
<html>
    <head>
        <title>Home</title>
        <meta charset="utf-8">
        <link rel="stylesheet" href="reset.css">
        <link rel="stylesheet" href="base3.css">                  
    </head>
    
    	<body>
    	  	<div id="logo">
            	<img src="images/logo.png" width="60" height="60" alt="SFH"/>
            </div>            	
            <nav>
                 <ul>
                    <li><a href="#">ABOUT</a></li>
                    <li><a href="#">LEARNING</a></li>
                    <li><a href="#">PROJECTS</a></li> 
                    <li><a href="#">CONTACT</a></li>    
                </ul>     
            </nav>
            
		</body>
</html>


CSS
@charset "utf-8";
/* CSS Document */

body {
	font-family: segoe ui, helvetica, lato, sans-serif;	
	background-color: #E9E9E9;
}

#logo {
	height: 60px;
	width: 60px;
	left: 50%;
	background-color: green;
	position: fixed;
	margin-top: 50px;
	
	}

nav {
	z-index: 10;
	background-color: #008cff;
	height: 65px;
	position: fixed; 
	left: 0;
    top: 0;
	width: 100%;
	box-shadow: 0px 2px 5px #949494; 
}

nav ul {
	height: 65;
	width: 660px;
	margin: auto;
}

nav ul li {
	list-style-type: none;
	width: 110px;
	float: left;
	text-align: center;
	font-size: 1.2em;
	font-weight: 450;
}
	
nav ul li:nth-of-type(3) {
  margin-left: 100px;
}
	
nav a {
	text-decoration: none;
	color: #F1F1F1;
	line-height: 65px; 
	display: block;	
}

nav a:hover {
	color: white;
	background-color: #007CE3;	
}

nav ul li ul {
	display: none;	
}

nav ul li:hover ul {
	display: block;	
	}
Posted
Comments
Sergey Alexandrovich Kryukov 2-Dec-15 16:17pm    
Do you mean vertical centering, horizontal, or both? Vertical positioning sometimes needs a touch of JavaScript, did you consider it? Anyway, it would be good to have some sample of the layout you want, precisely.
—SA
Gokulprasad05 21-Dec-15 6:47am    
can u able to post what is exact output/ answer you need in above coding. Plz send image of url

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900