简体   繁体   English

在元素指令上添加CSS

[英]Adding css on the element directive

I have this menu directive , that is basically absolutely positioned menu popping up when the html elements are clicked on the page. 我有这个menu directive ,当在页面上单击html元素时,基本上是绝对定位的菜单弹出。 On the html page, it is declared like this: 在html页面上,其声明如下:

<menu></menu>

and it works fine. 而且效果很好。 The only problem I have with this approach is that this new menu html element is also a block element and as such it creates empty space. 我对这种方法唯一的问题是,这个新menu html元素也是一个block元素,因此它会创建空白空间。 To fix this, I can add css rule 为了解决这个问题,我可以添加CSS规则

menu {
  position absolute;
}

or maybe add a custom class: 或添加一个自定义类:

.menu {
  position absolute;
}

<menu class="menu"></menu>

What I don't know, is it in the spirit of Angular to take these approaches or is there a better solution ? 我不知道,采用Angular的精神是采用这些方法还是有更好的解决方案?

Apply 0 margin and padding: 应用0边距和填充:

menu{
  margin: 0;
  padding: 0;
}

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

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