468,505 Members | 1,827 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

Css Style active link

Fary4u
273 100+
using asp while condition
how can i write perticular link as a selected value ?

Expand|Select|Wrap|Line Numbers
  1. <a class="mainlevel" href="p.asp?strCat=<%= strcat%>">
  2. <%= strcat %></a>
  3.  
using CSS style sheet

Expand|Select|Wrap|Line Numbers
  1. A.mainlevel:link {
  2. DISPLAY: block
  3. }
  4. A.mainlevel:visited {
  5. DISPLAY: block; TEXT-DECORATION: none
  6. }
  7. A.mainlevel:active {
  8. BORDER-LEFT: 5px; 
  9. }
  10.  
Aug 19 '10 #1
1 3470
azrar
11
Assuming you are creating a menu with multiple links

There are two ways you can do it.

First way is completely ASP:
Expand|Select|Wrap|Line Numbers
  1.  
  2. ' assuming you are already displaying the category based on a value in the querystring
  3. current_cat_id = request.QueryString("cat")
  4.  
  5. DO WHILE NOT rsLinks.eof
  6.   cat_id = rs("cat_id").value
  7.   cat_title = rs("cat_title").value
  8.   css_class = ""
  9.   If Cstr(cat_id) = Cstr(current_cat_id) Then
  10.     css_class = " active" 'note the space, it is needed to separate the two class names (mainlevel and active)
  11.   End IF
  12.   response.write "<a href='p.asp?cat=" & rs("cat").value & "' class='mainlevel" & css_class & "'>" & cat_title & "</a>"
  13.   rs.movenext
  14. Loop
  15.  
Note that you would need to make an "active" class in your CSS file. Like this:

a.active {border-left:5px solid #333;}


The other way is clever combo of ASP and CSS, but has some drawbacks.

Include the following CSS declaration in your ASP page:
Expand|Select|Wrap|Line Numbers
  1. a[href='<%=request.ServerVariables("SCRIPT_NAME")%>'] {border-left:5px solid #333;}
  2.  
This method only works if you are linking putting the full virtual path in your links (which is a good practice to do anyway). Meaning, if your links point to "/p.asp" instead of "p.asp". Also it will not work in IE 6.
Aug 19 '10 #2

Post your reply

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

Similar topics

36 posts views Thread by Peter Brause | last post: by
4 posts views Thread by Laiverd.COM | last post: by
6 posts views Thread by Carla | last post: by
4 posts views Thread by crhaynes | last post: by
2 posts views Thread by David W | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.