如何动态添加css类到navagion栏? [英] How dynamic add css class to navagion bar?
本文介绍了如何动态添加css类到navagion栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在用户控制文件(ascx)中有此代码,我希望当前访问的页面具有类活动
if I have this code in a user control file(ascx), I want the page current visited has class "active"
<ul>
<li class="active"><a href="a.html">Home</a></li>
<li><a href="b.html">About Us</a></li>
</ul>
例如:当我访问时b.html,html源应该是:
for example: when I visited b.html, the html source should be:
<ul>
<li ><a href="a.html">Home</a></li>
<li class="active"><a href="b.html">About Us</a></li>
</ul>
推荐答案
我认为更好的方法是在CSS中使用伪代码而不更改html源代码
ex:
I think the better ways is to use pseudo code in CSS without changing the html source
ex:
<style>
.active a:visited
{
add css for visited
}
</style>
tha不是重点。
为了将css类设置为
- 项,我必须这样做:
tha's not the point.
In order to set css class to
- item, I have to this work like this:
<% if(['some case']) { %>
<li class="active">
<% } else { %>
<li>
<% } %>
我认为关键是如何判断是否要添加css的情况我想怎么知道我现在正在加载哪个页面?
这不像news_list .aspx?id = 14我可以通过querystring添加css类,
我必须像news_list.aspx,index.aspx ...
这篇关于如何动态添加css类到navagion栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文