编写 stackoverflow 风格“问题”的最佳方法; /‘标签’ 翻转按钮

发布于 2024-07-11 20:45:18 字数 983 浏览 6 评论 0原文

实现像 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 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(5

    凉墨 2024-07-18 20:45:18

    链接上的悬停效果不需要 JavaScript。 使用 :hover pseudo-class

    a:hover {
        background-color:#FF9900; 
    }
    

    只需 菜单中,使用无序列表导航是很常见的。

    There's no javascript needed for hover effects on links. Just use the :hover pseudo-class:

    a:hover {
        background-color:#FF9900; 
    }
    

    Regarding the menu, it is quite common to implement navigation using unordered lists.

    漫漫岁月 2024-07-18 20:45:18

    使用 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.

    揽月 2024-07-18 20:45:18

    分解它,它的 css 驱动:

    .primarynav li {
        margin-right:7px;
    }
    .primarynav li:hover {
       background-color:#FF9900;
    }
    

    Firebug 是我的朋友。

    然而,没有理由不能用 javascript 来完成它

    jQuery(function($){ 
          $("ul#nav li").each(function(i,v){ 
               $(v).hover(function(){ 
                  $(v).addClass("hovered"); 
               },function(){ 
                  $(v).removeClass("hovered");
               }); 
          });
    });
    

    Decomposing it, its css driven:

    .primarynav li {
        margin-right:7px;
    }
    .primarynav li:hover {
       background-color:#FF9900;
    }
    

    Firebug is my friend.

    However, there's no reason why it couldn't be done with javascript

    jQuery(function($){ 
          $("ul#nav li").each(function(i,v){ 
               $(v).hover(function(){ 
                  $(v).addClass("hovered"); 
               },function(){ 
                  $(v).removeClass("hovered");
               }); 
          });
    });
    
    小糖芽 2024-07-18 20:45:18

    仅CSS:

    a.tagLink {
        background-color: red;
    }
    
    a.tagLink:hover {
        background-color: blue;
    }
    

    CSS only:

    a.tagLink {
        background-color: red;
    }
    
    a.tagLink:hover {
        background-color: blue;
    }
    
    蹲在坟头点根烟 2024-07-18 20:45:18

    您不需要为此使用 JavaScript; 一些简单的 CSS 就足够了:

    a:hover {
        background-color: /* something magical */;
    }
    

    注意选择器的“:hover”部分; 这就是神奇之处,它也适用于非 元素,尽管某些旧版本的 IE 会忽略链接以外的任何内容。

    显然,您可以在选择器中组合其他位,以将这种效果限制在导航链接或您想要实现的任何效果上。

    You don't need to use JavaScript for this; some simple CSS will suffice:

    a:hover {
        background-color: /* something magical */;
    }
    

    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.

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文