【问题标题】:How do i change the width/padding of a p-menu component?如何更改 p-menu 组件的宽度/填充?
【发布时间】:2018-11-19 07:57:46
【问题描述】:

我用 primeNG 的 p-menu 组件制作了一个菜单,我希望将菜单项向左移动一点。我认为我应该为此使用填充,我尝试了以下方法将其移动了几个像素。

<p-menu [model]="items" [style]="{minWidth:'18.8em', background: 'white', 
                              padding: .625em 0 0 0}"></p-menu>

但这给了我一个语法错误,这是堆栈跟踪:

[错误->]) 在 JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents (compiler.js:22639) 在 compiler.js:22549 在 Object.then (compiler.js:206) 在 JitCompiler.push../node_modules/@angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:22548)

菜单本身如下所示:

我做错了什么?

【问题讨论】:

  • 不,同样的错误:(

标签: javascript angular primeng


【解决方案1】:

&lt;p-menu&gt; 有“ui-menu”。使用

在组件样式表中为其设置样式
  • ::ng-deep

    ::ng-deep .ui-menu { padding: .625em 0 0 0 }

Demo

  • ViewCansulation 已关闭:

    import { ViewEncapsulation } from '@angular/core';

    ...
    @Component({
      ...
      encapsulation: ViewEncapsulation.None
    })
    

    .ui-menu { padding: .625em 0 0 0 }

Demo

【讨论】:

  • 这没有语法错误,但也不起作用。无论我填写什么,0.625em 或 1000 em 填充保持不变......我也尝试在它后面添加 !important,没有效果。
  • ::ng-deep .ui-menu { ?
猜你喜欢
  • 2019-04-21
  • 2019-11-30
  • 2017-01-03
  • 1970-01-01
  • 2011-04-08
  • 2014-08-05
  • 2020-03-09
  • 2021-05-01
  • 2010-10-21
相关资源
最近更新 更多