472,993 Members | 2,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 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 1964
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.