Jump to content

controling the bold display of a menu


learningPHP1

Recommended Posts

Hello,

 

I have a menu and using css to control the display. problem area: mouse over menu and bolding. for most part the menu works, what i like to do is prevent the bold (mouse over) from pushing surrounding menus to make space to display the bold. I know i need to somehow expand the menu spaceing so that when the mouse over wont pushing the other menus over but cant seem to hit that number. any ideas?

<style rel="stylesheet" type="text/css">
			#navcontainer ul { list-style-type: none; margin: 0; padding: 0; }
			#navcontainer ul li {display: inline;  }
			#navcontainer ul li a { text-decoration: none;  font-size: 18px; 
				color: black; background-color: #FFFFFF;}
			#navcontainer ul li a:hover { color: darkblue; 	background-color: #FFFFFF; text-decoration:underline; font-weight:bold;}
		</style>
		
	</head>

	<body>
		<div id="navcontainer">
			<ul>
				<li> <a href="#"> Home</a></li>
				<li>|<a href="#"> Project listing</a></li>
				<li>|<a href="#"> Directory</a></li>
				<li>|<a href="#"> Create project</a></li>
				<li>|<a href="#"> My project</a></li>
			</ul>
		</div> 
	</body>
</html>
Link to comment
Share on other sites

Currently you have set no width so it'll only consume the space it needs to fit the text. When you mouseover the text it becomes bold, which requires more space and so the text shifts slightly to the right. To prevent this you need to define a width.

Also rather than hard-coding a pipe character to separate each item in menu, use borders instead

 

Working example

http://jsfiddle.net/7r6pX/1/

Edited by Ch0cu3r
Link to comment
Share on other sites

Thanks for the replay chocu3r but now i have large gaps between menus..not very attractive looking.

 

Currently you have set no width so it'll only consume the space it needs to fit the text. When you mouseover the text it becomes bold, which requires more space and so the text shifts slightly to the right. To prevent this you need to define a width.

Also rather than hard-coding a pipe character to separate each item in menu, use borders instead

 

Working example

http://jsfiddle.net/7r6pX/1/

Link to comment
Share on other sites

  • 2 weeks later...
    <style rel="stylesheet" type="text/css">
    #navcontainer ul { list-style-type: none; margin: 4; padding: 4; width: 100%;}
    #navcontainer ul li {display:inline-block; width: 7%; text-align: center; border-right: 1px solid #000; margin:0; padding: 2px 0; }
    #navcontainer ul li a { text-decoration: none; font-size: 18px;
    color: black; background-color: #FFFFFF;}
    #navcontainer ul li a:hover { color: darkblue; background-color: #FFFFFF; text-decoration:underline; font-weight:bold;}
    </style>
    </head>
     
    <body>
    <div id="navcontainer">
    <ul>
    <li> <a href="#"> Home</a></li>
    <li>|<a href="#"> Project listing</a></li>
    <li>|<a href="#"> Directory</a></li>
    <li>|<a href="#"> Create project</a></li>
    <li>|<a href="#"> My project</a></li>
    </ul>
    </div>
    </body>
    </html>

That is because #navcontainer ul li does not have a defined width attribute so it will take up all the space you are allowing to. Notice the width: 7%; the padding and the margin. By setting the width to 7% you are imposing specific width.

I hope I could help

Edited by Triniton722
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.