Solved

CSS priority

Posted on 2009-05-06
3
321 Views
Last Modified: 2012-05-06
All,

I'm having a problem getting a css menu to format properly.  There's one large menu item that's pushing all of the other menu items out of alignment.  If I expand the width of all menu items, the menu becomes too large for the page.  If I try to override just that one menu items' width, with the "style" tag, css expands the width of the menu item but flows the text at the original setting.  Any suggestions?

The code is below, and thanks!
CSS:

#menu ul

{

	list-style: none;

	padding: 0;

	margin: 0;

} 
 

#menu li

{

	float:left;

	margin: 0 0 0.15em;

	font-size:10pt;

	font-weight:bold;

	font-family:arial, helvetica, san-serif;

	
 

} 
 

#menu li a

{

	background: #e85f31;

	height: 2em;

	line-height: 2em;

	float: left;

	width: 10em;

	display: block;

	color: #ffffff;

	text-decoration: none;

	text-align: center;

} 
 

HTML:

<div id="menu">

<ul>

<li><a href="#">Short</a></li>

<li style="width:15em;"><a href="#">Long, long, long, long menu item</a></li>

<li><a href="#">Short</a></li>

<li><a href="#">Short</a></li>

<li><a href="#">Short</a></li>

</ul>

</div><!-- end menu -->

Open in new window

0
Comment
Question by:Raydot
3 Comments
 
LVL 13

Accepted Solution

by:
Brian Withun earned 250 total points
Comment Utility
I think padding is the trick here:

#menu li a
{
      background: #e85f31;
      height: 2em;
      line-height: 2em;
      float: left;
      /*width: 6em;*/
      display: block;
    padding: 0 1em;
      color: #ffffff;
      text-decoration: none;
      text-align: center;
}
<html>

<head>

<style>
 

#menu ul

{

	list-style: none;

	padding: 0;

	margin: 0;

} 

 

#menu li

{

	float:left;

	margin: 0 0 0.15em;

	font-size:10pt;

	font-weight:bold;

	font-family:arial, helvetica, san-serif;

	border-left: 1px solid white;

    border-right: 1px solid white;

 

} 

 

#menu li a

{

	background: #e85f31;

	height: 2em;

	line-height: 2em;

	float: left;

	/*width: 6em;*/

	display: block;

    padding: 0 1em;

	color: #ffffff;

	text-decoration: none;

	text-align: center;

} 

 

.longlong

{

    text-decoration:underline;

}
 

</style>

</head>

<body>
 

<div id="menu">

<ul>

<li><a href="#">Short</a></li>

<li><a href="#">Long, long, long, long menu item</a></li>

<li><a href="#">Short</a></li>

<li><a href="#">Short</a></li>

<li><a href="#">Short</a></li>

</ul>

</div><!-- end menu -->
 

</body>

</html>

Open in new window

longlong.jpg
0
 
LVL 7

Expert Comment

by:ycTIN
Comment Utility
inline-style have are highest priority


        <li>
            <a href="#" style="width:auto;">Long, long, long, long menu item</a>
        </li>
0
 
LVL 3

Author Closing Comment

by:Raydot
Comment Utility
Thanks!  Why doesn't it need to have a width?
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

"I want to put my photos online, but I don't want them stolen.  What settings should I use?" When You Put Photos Online First and foremost, any digital file published on the WWW can be copied, stored, modified, retransmitted, etc.  Remember Naps…
This article discusses four methods for overlaying images in a container on a web page
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now