在 Angular Material 排序标题中创建自定义箭头 [英] Creating custom arrow in Angular Material sort header

查看:24
本文介绍了在 Angular Material 排序标题中创建自定义箭头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建 Angular 5 项目,我想在排序标题中创建自定义排序图标以实现此效果 https://fontawesome.com/icons/caret-up?style=solid.我不想有这个默认箭头.

I am creating Angular 5 project and I wanted to create custom sort icon in sort header to achieve this effect https://fontawesome.com/icons/caret-up?style=solid. I don't want to have this default arrow.

我尝试更改 css 样式,但似乎不起作用.或者有什么办法可以使用JS自定义替换这个图标?

I tried to change css style, but it seems not to work. Or maybe is there any way to replace this icon by custom using JS?

::ng-deep  {

    .cdk-visually-hidden {
        border: 0;
        clip: rect(0 0 0 0);
        height: 1px;
        margin: -1px;
        overflow: hidden;
        padding: 0;
        position: absolute;
        width: 1px;
    }

    .mat-sort-header-stem {
        background: none;
        display: none !important;
    }

    .mat-sort-header-container {
        position: relative;
    }
    .mat-sort-header-indicator {

      transform: translateY(0px) !important;
    }

    .mat-sort-header-arrow {
        position: absolute;
        right: 20px;
        transform: translateY(0%) !important;
    }


  } 

感谢您的任何建议.

编辑.

如果有人遇到这个问题,我通过向 mat-sort-header 元素添加自定义指令来解决它.我还传递给指令排序方向(ASC 或 DESC).最后根据方向,我使用纯 CSS 自定义了我的排序图标.

If someone has this problem, I solved it by adding custom directive to mat-sort-header element. I also passed to directive the sort direction (ASC or DESC). Finally based on the direction I customized my sort icon using pure CSS.

推荐答案

看看是否对您有帮助

.triangle {
    overflow: hidden;
    position: relative;
    margin: 2em auto;
    border-radius: 20%;
    transform: translateY(50%) rotate(30deg) skewY(30deg) scaleX(.866);
    width: 5em;
    height: 5em;
}

.triangle:before {
    border-radius: 20% 20% 20% 53%;
    transform: scaleX(1.155) skewY(-30deg) rotate(-30deg) translateY(-42.3%) skewX(30deg) scaleY(.866) translateX(-24%);
    position: absolute;
    background: #ccc;
    pointer-events: auto;
    content: '';
    width: 5em;
    height: 5em;
}

.triangle:after {
    border-radius: 20% 20% 53% 20%;
    transform: scaleX(1.155) skewY(-30deg) rotate(-30deg) translateY(-42.3%) skewX(-30deg) scaleY(.866) translateX(24%);
    position: absolute;
    background: #ccc;
    pointer-events: auto;
    content: '';
    width: 5em;
    height: 5em;
}

<div class="triangle"></div>

这篇关于在 Angular Material 排序标题中创建自定义箭头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆