简体   繁体   English

PrimeNg 图标未显示(复选框和选择)

[英]PrimeNg Icons Not Showing (Checkbox and Select)

选中框并选择 sans 图标。 Checked box and select sans icons.选中框并选择 sans 图标。

I've added the primeicons library per: https://github.com/primefaces/primeng/wiki/Migration-Guide我已经添加了primeicons库: https : //github.com/primefaces/primeng/wiki/Migration-Guide

However, something is still a muck, I can't get the icons with show up.但是,有些事情仍然很糟糕,我无法显示带有图标的图标。

package.json:包.json:

...
"primeicons": "^1.0.0-beta.10",
"primeng": "6.1.2",

also have, not sure if relevant.也有,不确定是否相关。 Doesn't seem like it's overwriting the css but possible似乎没有覆盖 css 但可能

"font-awesome": "4.7.0",
"@angular/material": "^6.4.7",

html: html:

<p-checkbox binary="true" label="Match Note"></p-checkbox>

html showing icon class - from dev tools: html 显示图标类 - 来自开发工具:

<span class="ui-chkbox-icon ui-clickable pi pi-check" ng-reflect-klass="ui-chkbox-icon ui-clickable" ng-reflect-ng-class="[object Object]"></span>

css - from dev tools: css - 来自开发工具:

.ui-chkbox .ui-chkbox-icon {
    display: block;
}
<style>…</style>
.ui-widget, .ui-widget * {
    box-sizing: border-box;
}
<style>…</style>
*, *::before, *::after {
    box-sizing: border-box;
}
<style>…</style>
.ui-chkbox .ui-chkbox-box {
    width: 1.125em;
    height: 1.125em;
    line-height: 1.125em;
    border-radius: 2px;
    text-align: center;
}
<style>…</style>
.ui-chkbox-box.ui-state-active, .ui-radiobutton-box.ui-state-active {
    border: 1px solid #156090;
    background: #186ba0;
    color: #FFFFFF;
}
<style>…</style>
.ui-state-active {
    border-color: #bebebe;
    background-color: #d6d6d6;
    color: #212121;
}
<style>…</style>
.ui-state-default {
    border: 1px solid #d6d6d6;
    background-color: #ffffff;
    color: #555555;
}
<style>…</style>
.ui-widget {
    /* font-family: "Roboto", "Trebuchet MS", Arial, Helvetica, sans-serif; */
    font-size: 1em;
}
<style>…</style>
.ui-chkbox {
    display: inline-block;
    cursor: pointer;
    vertical-align: middle;
    margin-right: .25em;
    -ms-user-select: none;
    user-select: none;
    -moz-user-select: none;
    -webkit-user-select: none;
}
<style>…</style>
.ui-widget {
    /* font-family: "Roboto", "Trebuchet MS", Arial, Helvetica, sans-serif; */
    font-size: 1em;
}
<style>…</style>
.mat-card {
    background: white;
    color: rgba(0, 0, 0, 0.87);
}
<style>…</style>
.mat-card {
    /* font-family: Roboto,"Helvetica Neue",sans-serif; */
}
Style Attribute {
    visibility: visible;
}
<style>…</style>
.mat-expansion-panel {
    background: white;
    color: rgba(0, 0, 0, 0.87);
}
<style>…</style>
.mat-expansion-panel {
    background: #fff;
    color: rgba(0,0,0,.87);
}
<style>…</style>
body {
    margin: 0;
    font-family: 'Roboto', sans-serif;
}
<style>…</style>
body {
    margin: 0;
    /* font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; */
    i": ;
    */: ;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: #212529;
    text-align: left;
    background-color: #fff;
}
<style>…</style>
html {
    font-family: sans-serif;
    line-height: 1.15;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    -ms-overflow-style: scrollbar;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
<style>…</style>
body {
    margin: 0;
    font-family: 'Roboto', sans-serif;
}
<style>…</style>
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
    i": ;
    */i": ;
    */: ;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: #212529;
    text-align: left;
    background-color: #fff;
}
<style>…</style>
html {
    font-family: sans-serif;
    line-height: 1.15;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    -ms-overflow-style: scrollbar;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
<style>…</style>
body {
    margin: 0;
    font-family: 'Roboto', sans-serif;
}
<style>…</style>
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
    i": ;
    */: ;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: #212529;
    text-align: left;
    background-color: #fff;
}

You can also include primeng.css, theme and primengicons under 'styles' section in angular.json.您还可以在 angular.json 的“样式”部分下包含primeng.css、主题和primengicons。

"styles": [
     "../node_modules/primeng/resources/primeng.min.css",
     "../node_modules/primeng/resources/themes/nova-light/theme.css",
     "../node_modules/primeicons/primeicons.css"
]

尝试在 style.css 文件中添加导入

@import '~primeicons/primeicons.css';

change span font family in style.css to将 style.css 中的 span 字体系列更改为

span{
    font-family:'primeicons' !important
}

If you are still not able to see the icons and styling after applying the suggestions in the accepted answer, try adding the css entries into your styles.scss file, that is what it took in my case.如果在接受的答案中应用建议后仍然无法看到图标和样式,请尝试将 css 条目添加到您的 styles.scss 文件中,这就是我的情况。

@import  "~primeicons/primeicons.css";
@import  "~primeng/resources/themes/saga-blue/theme.css";
@import  "~primeng/resources/primeng.min.css";
@import  "~primeflex/primeflex.css";

This might not be directly relevant, but I was trying to solve a similar problem with Search and placing a search icon within the text input.这可能不是直接相关的,但我试图用搜索解决类似的问题,并在文本输入中放置一个搜索图标。

The problem for me was z-index;我的问题是 z-index; the icon was there, but it was hidden behind the search input box!!图标在那里,但它隐藏在搜索输入框后面!!

So setting the icon's z-index via CSS solved the issue (in my case, to 1).所以通过 CSS 设置图标的 z-index 解决了这个问题(在我的例子中,为 1)。

.pi .pi-search {
z-index: 1;
}

In case someone still facing this issue, do check webpack loader config.如果有人仍然面临这个问题,请检查 webpack loader 配置。

For me the issue was related to webpack loader:对我来说,这个问题与 webpack 加载器有关:

After updating my code of webpack module loader from :从以下位置更新我的 webpack 模块加载器代码后:

            {
                test: /\.(png|woff|woff2|eot|ttf|svg)$/, 
                use: ["url-loader", "file-loader"]
            }

to:到:

            {
                test: /\.(png|woff|woff2|eot|ttf|svg)$/,
                loader: 'url-loader'
            },
            {
                test: /\.(ico|jpe?g|png|gif|webp|svg|mp4|webm|wav|mp3|m4a|aac|oga)(\?.*)?$/,
                loader: "file-loader"
            }

Icons started loading properly.图标开始正确加载。

You have to add DropdownModule and this one CheckboxModule and then this section to your styles.css file.您必须将DropdownModule和这个CheckboxModule以及此部分添加到您的styles.css文件中。

@import "~primeicons/primeicons.css";
@import "~primeng/resources/themes/saga-blue/theme.css";
@import "~primeng/resources/primeng.min.css";

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM