编写 stackoverflow 风格“问题”的最佳方法; /‘标签’ 翻转按钮
实现像 Stackoverflow 顶部的“问题”、“标签”、“用户”那样的滚动“按钮”的最佳方法是什么?
它实际上是这样实现的:
<div class="nav">
<ul class="primarynav">
<li class="">
<a href="/questions">Questions</a>
</li>
<li class="">
<a href="/tags">Tags</a>
</li>
<li class="">
<a href="/users">Users</a>
</li>
<li class="">
<a href="/badges">Badges</a>
</li>
<li class="">
<a href="/unanswered">Unanswered</a>
</li>
</ul>
我有点放弃尝试为此寻找 javascript,因为所有 javsascript 似乎都在一行上。
我只是想知道人们认为实现这样的简单按钮最简单/最可靠的方法是什么。
我发现很有趣的是 stackoverflow 使用
而不是像
这样的东西。 很好奇为什么......PS。 我正在使用 ASP.NET——目前没有其他库,例如 JQuery,但如果有帮助的话我愿意尝试类似的东西。
Whats the best way to implement rollover 'buttons' like Stackoverflow has for 'Questions', 'Tags', 'Users' at the top.
It is actually implemented like this :
<div class="nav">
<ul class="primarynav">
<li class="">
<a href="/questions">Questions</a>
</li>
<li class="">
<a href="/tags">Tags</a>
</li>
<li class="">
<a href="/users">Users</a>
</li>
<li class="">
<a href="/badges">Badges</a>
</li>
<li class="">
<a href="/unanswered">Unanswered</a>
</li>
</ul>
I kinda gave up trying to find the javascript for this since all the javsascript seems to be on one line.
I was just wondering what people think is the simplest / most reliable way to implement simple buttons like this.
I found it very interesting that stackoverflow is using <li>
and not something like <span>
. Curious as to why...
PS. I'm using ASP.NET -- currently with no other libraries such as JQuery, but willing to try something like that if it'll help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
链接上的悬停效果不需要 JavaScript。 使用 :hover pseudo-class:
只需 菜单中,使用无序列表导航是很常见的。
There's no javascript needed for hover effects on links. Just use the :hover pseudo-class:
Regarding the menu, it is quite common to implement navigation using unordered lists.
使用 li 元素是有意义的,因为这些是(链接)列表,赋予链接语义。 当事物被语义标记时,非视觉浏览器可以理解文档,例如搜索引擎和使用屏幕阅读器的视力障碍者。
using li elements makes sense because these are lists (of links), giving the links semantics. When things are semantically marked up, the document can be understood by non-visual browsers, such as search engines and visualy-impared persons using screen-readers.
分解它,它的 css 驱动:
Firebug 是我的朋友。
然而,没有理由不能用 javascript 来完成它
Decomposing it, its css driven:
Firebug is my friend.
However, there's no reason why it couldn't be done with javascript
仅CSS:
CSS only:
您不需要为此使用 JavaScript; 一些简单的 CSS 就足够了:
注意选择器的“
:hover
”部分; 这就是神奇之处,它也适用于非元素,尽管某些旧版本的 IE 会忽略链接以外的任何内容。
显然,您可以在选择器中组合其他位,以将这种效果限制在导航链接或您想要实现的任何效果上。
You don't need to use JavaScript for this; some simple CSS will suffice:
Note the "
:hover
" part of the selector; that's the magic bit, and it works on non-<a>
elements, too, although some older versions of IE will disregard it for anything other than a link.Obviously, you can combine additional bits in the selector to limit this effect to your navigation links, or whatever you want to achieve.