简体   繁体   English

如何在侧面导航栏中的活动链接下划线? 在Angle App中使用材质设计

[英]How can I underline the active link in my side nav bar? Using material design in angular app

<div class="mt-3">
  <mat-nav-list>

      <a mat-list-item class="ml-2" style="font-size:15px;" (click)='paycard.html'>
          SERVICE
        </a>
      <a mat-list-item class="ml-2" style="font-size:15px;" (click)='paycard.html'>
          BILLING
        </a>
      <a mat-list-item class="ml-2" style="font-size:15px;" (click)='paycard.html'>
          OIL TICKETS
        </a>
      <a mat-list-item class="ml-2" style="font-size:15px;" (click)='paycard.html'>
          MY TIME
        </a>
      <a mat-list-item class="ml-2" style="font-size:15px;" (click)='paycard.html'>
          APPROVE TIME
        </a>
      <a mat-list-item class="ml-2" style="font-size:15px;" (click)='paycard.html'>
          EMPLOYEE LIST
        </a>

snippet of my html navigation page I just want to underline the active link but not quite sure how to do that within an angular app using material design. 我的html导航页面的摘要,我只想在活动链接下划线,但不太确定如何使用材质设计在有角度的应用程序中执行此操作。 Also if there is a way to collapse it I would like to know that too. 另外,如果有一种方法可以使它崩溃,我也想知道。 Thank you. 谢谢。

As found in the Angular Routing and Navigation documentation, you use the routerLinkActive directive. 如在Angular 路由和导航文档中routerLinkActive ,您可以使用routerLinkActive指令。

<mat-nav-list>
   <a mat-list-item 
        routerLink="/paycard"
        routerLinkActive="active_route"> Paycard </a>
</mat-nav-list>

This will add the .active_route class to your active route. 这会将.active_route类添加到您的活动路由中。 Then you can style it as you'd like: 然后,您可以根据需要设置其样式:

.active_route {
  text-decoration: underline;
}

If you have similar links, you may need to use {pathMatch: full} in the router link options (eg if you have routes "/pay" and "/pay/card".) 如果您具有类似的链接,则可能需要在路由器链接选项中使用{pathMatch: full} (例如,如果您的路由为“ / pay”和“ / pay / card”。)

If you do the routing in the tag you can add the routerLinkActive attribute to apply a css class when the route is active. 如果您在标记中进行路由,则可以添加routerLinkActive属性,以在路由处于活动状态时应用css类。

In you case the would look something like this: 在您的情况下,将如下所示:

    <a mat-list-item class="ml-2" style="font-size:15px;" (click)='paycard.html'
 routerLink="service" routerLinkActive="<css class you want to apply when active"> SERVICE </a>

For more information have a look here 欲了解更多信息,请看这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用角度材料设计类似Google+的导航栏 - How can I design a Google+ like, nav-bar using angular material 如何将导航栏上的用户图标移到中心? 以及如何为侧面导航栏创建边框? - how can I get my user icon on the side nav bar to the center? and how can i create border for the side nav bar? 我有一个导航栏,可以更改iframe的src,如何更改活动链接颜色? - I have a nav bar that changes the src of an iframe, how can i change the active link color? 如何为导航栏文本的下拉菜单文本和中心下拉菜单文本重复下划线CSS? - How can I repeat the underline CSS for my nav bar text for my drop down menu text and centre drop down menu text? 我如何在我的引导程序中强调当前页面<nav></nav> - How i can underline the current page inside my bootstrap <nav> 当用户在导航栏上突出显示网页文本时,如何添加下划线颜色? - How can I add an underline colour when the user highlights over the webpage text on nav bar? 如何使用按钮创建导航栏或如何更改导航栏中文本的字体大小 - How do I create a Nav bar using buttons or how can I change the font size of the text in my nav bar 如何使用JQuery在导航栏中单击时滑动一个滑动条 - How to can I have a sliding bar that slides on click in my nav bar using JQuery 角材料导航栏不起作用 - Angular material nav bar not working 样式角度材料导航栏 - Style Angular Material Nav bar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM