html - "cursor: pointer"根本不工作

标签 html css angular

这是我的 Angular 模板代码:

   <!-- Modal -->
   <ng-template #levelsmodal let-c="close" let-d="dismiss">
        <div class="modal-header">
         Select the levels you want to show in the table and chart
        </div>
        <div id="segments-modal" class="modal-body">
          <div class="row margin" *ngFor="let level of config?.data?.groups; let i = index" (click)="selectLevel(level)">
                <div  class="colorspan" [style.backgroundColor]="level.active ? colors[i] : 'gray'" class="colorspan">
                </div>
                <span class="level-labels pointer-cursor" [innerHTML]="getLabel(level)" ></span> 
            </div>
        </div>
        <div class="modal-footer">
            <button class="btn btn-success" (click)="c()">Close</button>
        </div>
      </ng-template>    

“pointer-cursor”类非常简单:

.pointer-cursor{
    cursor: pointer !important; 
    z-index: 500;
}

添加 z-index 只是为了尝试它是否可以有所作为,但事实并非如此。我还尝试将此类应用于包装器 div 等其他部分,但它就是行不通。我一直看到正常的“文本光标”而不是指针...

有人知道为什么会这样吗?

最佳答案

试试看

::ng-deep .pointer-cursor{
   cursor: pointer !important; 
z-index: 500;
}

编辑 ::ng-deep 组合器 ( https://angular.io/guide/component-styles#deprecated-deep--and-ng-deep ) 确保定义的样式适用于组件的所有子元素,而不仅仅是组件直接创建的元素。

因为你想要在 ng-template 标签中设置样式的元素(所以它不直接属于组件),你需要使用它来设置元素的样式

关于html - "cursor: pointer"根本不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49366064/

相关文章:

javascript - 如何在域的所有页面上运行javascript脚本?

html - 对齐标题旁边的文本

javascript - 如何防止在图形区域或浏览器窗口调整大小时隐藏 highcharts 工具提示弹出窗口?

css - 自动尺寸输入字段

html - 如何处理子页面上的多个h1元素

html - 为什么这条白线出现在我的 HTML 电子邮件签名上?

html - 仅在 IE 中居中网站

javascript - 在 Angular+Nativescript 中将项目添加到数据库时刷新列表查看项目

javascript - Angular 项目中 angular.json 中的 styles 和 stylePreprocessorOptions 有什么不同

Angular 6等待订阅完成