Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

CSS priority

Posted on 2009-05-06
3
326 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
ID: 24318562
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
ID: 24323230
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
ID: 31578644
Thanks!  Why doesn't it need to have a width?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Put shading on half of picture 8 51
A simple Float not working. 5 25
Can't get container centered 4 24
How to resize a div in html 3 37
When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

839 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