473,396 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Simple Menu using UL/LI and A

karlectomy
Hello,

I want to make the whole <li> element a link and clickable. here is my code that I have:
Expand|Select|Wrap|Line Numbers
  1. #nav {
  2. background-color:#99CCFF;
  3. border-color:#000066;
  4. border-style:solid;
  5. border-width:.75px;
  6. width:150px;
  7. height:700px;
  8. }
  9.  
  10. #menu {
  11.     list-style-type:none;
  12.     padding-left:4px;
  13.     margin:0px;
  14. }
  15.  
  16. #menuitem {
  17.  width:140px;
  18.  border-style:solid;
  19.  border-color:#000000;
  20.  border-width:.75px;
  21.  padding-top:5px;
  22. }
  23.  
  24. #nav a, #nav a:visited {
  25. text-decoration:none;
  26. color:#000000;
  27.  
  28. }
  29.  
  30. #menuitem li:hover {
  31.   background-color:#CCCCCC;
  32. }
  33.  
  34. <div id="nav">
  35.     <ul id="menu">
  36.         <a href="index.htm" id="menulink"><li id="menuitem">Home</li></a>
  37.         <a href="bio.htm" id="menulink"><li id="menuitem">Bio</li></a>
  38.         <a href="articles.php" id="menulink"><li id="menuitem">Articles</li></a>
  39.         <a href="clients.php" id="menulink"><li id="menuitem">Clients</li></a>
  40.         <a href="links.htm" id="menulink"><li id="menuitem">Links</li></a>
  41.     </ul>
  42. </div>
  43.  
Does anyone have any suggestions?
Nov 7 '07 #1
10 1982
drhowarddrfine
7,435 Expert 4TB
'id' is a unique name which is given to one element only. If you must use the same style for multiple elements, use 'class'.

You are using :hover for the <li> element. This will only work in modern browsers and not IE6.
Nov 7 '07 #2
'id' is a unique name which is given to one element only. If you must use the same style for multiple elements, use 'class'.

You are using :hover for the <li> element. This will only work in modern browsers and not IE.
I know I know, i was trying to use the hover for style. But I want to make the whole <li> clickable. Do you know how to do this?
Nov 7 '07 #3
drhowarddrfine
7,435 Expert 4TB
You cannot have the <a> outside the <li> because <a> will be treated as another element, which would be illegal for an <ul>.

So, <li><a href.......

Then, in css, you need to make the <a> extend the width of the <li>. But <a> is inline while <li> is block level. So:
ul li a{display:block;width:200px}

Another way to do that is position it:
ul li a{float:left;width:200px;}

The float is necessary to position it but you can use any positioning method, I think. Don't recall if you also have to position the <li> to the same width as the <a>.
Nov 7 '07 #4
You cannot have the <a> outside the <li> because <a> will be treated as another element, which would be illegal for an <ul>.

So, <li><a href.......

Then, in css, you need to make the <a> extend the width of the <li>. But <a> is inline while <li> is block level. So:
ul li a{display:block;width:200px}

Another way to do that is position it:
ul li a{float:left;width:200px;}

The float is necessary to position it but you can use any positioning method, I think. Don't recall if you also have to position the <li> to the same width as the <a>.
Ok, I'm a little slow. I'm creating a Vertical Menu... Not horizontal for which the float left is necessary.

Do you know how this could work with a vertical menu?
Nov 7 '07 #5
drhowarddrfine
7,435 Expert 4TB
Perhaps you read my post before I edited it. Use the css for 'display:block'.
Nov 7 '07 #6
Have I ever told you, you're my hero.

Thanks for pointing me in the right direction. That really helped a lot.

Remember, you are the wind beneath my wings.
Nov 7 '07 #7
Markus
6,050 Expert 4TB
Javascript would make that so easy! No need to expand the <a> n such.

Expand|Select|Wrap|Line Numbers
  1.  <script type="text/javascript" language="javascript">
  2.   function goToLink(url){
  3.     window.location = "http://"+url+""
  4.     }
  5.  </script>
  6.  
Expand|Select|Wrap|Line Numbers
  1. <a onclick="goToLink('url_here')">go to</a>
  2.  
Sorry if i strayed from your question.
Nov 7 '07 #8
Javascript would make that so easy! No need to expand the <a> n such.

Expand|Select|Wrap|Line Numbers
  1.  <script type="text/javascript" language="javascript">
  2.   function goToLink(url){
  3.     window.location = "http://"+url+""
  4.     }
  5.  </script>
  6.  
Expand|Select|Wrap|Line Numbers
  1. <a onclick="goToLink('url_here')">go to</a>
  2.  
Sorry if i strayed from your question.
I try to stay away from javascript. We got into a drunken argument and we don't really talk anymorre
Nov 7 '07 #9
drhowarddrfine
7,435 Expert 4TB
Javascript would make that so easy! No need to expand the <a> n such.

Expand|Select|Wrap|Line Numbers
  1.  <script type="text/javascript" language="javascript">
  2.   function goToLink(url){
  3.     window.location = "http://"+url+""
  4.     }
  5.  </script>
  6.  
Expand|Select|Wrap|Line Numbers
  1. <a onclick="goToLink('url_here')">go to</a>
  2.  
Sorry if i strayed from your question.
I don't see how all that is simpler than:
ul li a{display:block;width:200px}

Plus it works even if js is disabled.
Nov 7 '07 #10
I don't see how all that is simpler than:
ul li a{display:block;width:200px}

Plus it works even if js is disabled.
I concur with your findings
Nov 8 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: dr. zoidberg | last post by:
Hello, I'm creating simple menu. MySQL: +----+-----+----------------------+ | id | sid | Title | +----+-----+----------------------+ | 1 | 0 | Main Menu 1 | 2 | 0 | Main Menu 2 | ...
1
by: Michael Champagne | last post by:
Does anyone have any examples or links to examples of generating a simple unordered list menu with multiple levels from an XML file? We are redesigning the navigation on our website and I was...
1
by: BenOne© | last post by:
Hi all, I'm learning CSS, and relearning HTML so I can build a website for myself, and I was wondering if someone could help me with what seems like a simple layout that I want to maintain no...
3
by: trialanderror | last post by:
Both of these apply to using IE 6.0 or Netscape 7.x: First question: I am trying to set up a simple horizontal menu as a red strip across the browser window. Here is the relevant part of the...
17
by: Paul | last post by:
HI! I get an error with this code. <SCRIPT language="JavaScript"> If (ifp==""){ ifp="default.htm"} //--></SCRIPT> Basicly I want my iframe to have a default page if the user enters in...
6
by: Sergio | last post by:
for my web site I am looking for a simple PHP plain text menu system, the menu would have at least four levels and about 200 links, at starting only the main levels should appear, for example : ...
5
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files,...
22
by: tricard | last post by:
Good evening, I was thinking about making a very simple DOS based (console) menu for a project that i am working on, but I have no idea where to start for something like this. Does anyone have...
6
by: yefei | last post by:
i want to display a price lists according to the product groups the user select. the designer gave to me is to show the product groups use a tab menu, which can enlarge a little bit, when user...
4
by: Timmah1980 | last post by:
I'm sure this is a simple enough fix for someone out there, but I'm afraid it's beyond me! I'm putting together this simple menu for a client: http://www.timkeay.co.uk/mpc2/index.htm It...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.