简体   繁体   English

无法获取css以应用于Angular Component

[英]Cannot get css to apply to Angular Component

I've been stuck on this for a while. 我已经坚持了一段时间。

I created an Angular component called app-place-icon-avatar. 我创建了一个名为app-place-icon-avatar的Angular组件。

I would like the app-place-icon-avatar to be either 55px in height or 100% the height of the div. 我希望app-place-icon-avatar可以是55px的高度,也可以是div的高度的100%。

I've tried a bunch of things. 我尝试了很多东西。

Please see the screenshot for what I am referencing. 请参阅屏幕截图,了解我所引用的内容。

The html element shows 17px tall when I inspect it, but the css of 55px seems to be applied correctly. 当我检查它时,html元素显示17px高,但55px的css似乎正确应用。

I've tried applying ::host /deep/, ::host, applying a style directly to place-icon-avatar in the parent component's html. 我已经尝试应用:: host / deep /,:: host,将样式直接应用于父组件的html中的place-icon-avatar。

The css seems to be being applied when I inspect it. 我检查时似乎正在应用css。 It says height 100% on the right, but the actual app-place-icon-avatar is 17px no matter what I do. 它说右边的高度为100%,但无论我做什么,实际的app-place-icon-avatar都是17px。

I'm new to angular, and I'm sorry if I am missing something basic, but I've searched for a while and can't find anything that works. 我是棱角分明的新手,如果我遗漏了一些基本的东西,我很抱歉,但我已经搜索了一段时间,找不到任何有用的东西。

The reason I would like to make this component a certain height, is that it is easier to center it. 我想让这个组件达到一定高度的原因是它更容易居中。 Since the image within the app-place-icon-avatar is 55px, but the app-place-icon-avatar itself is only 17px high, it makes it difficult to center it vertically. 由于app-place-icon-avatar中的图像是55px,但app-place-icon-avatar本身只有17px高,因此很难将其垂直居中。 I would like to make it as simple as possible. 我想尽量简单。

:host /deep/ {
  height: 50px;
}

I am expecting the app-place-icon-avatar to be either 55px or 100% in height. 我期待app-place-icon-avatar的高度为55px或100%。 It is 17px no matter what I try. 无论我尝试什么,它都是17px。

https://imgur.com/qQBk3nh https://imgur.com/qQBk3nh

Jojofoulk gave me the answer, which was to change the displaymode to flex or block. Jojofoulk给了我答案,就是将displaymode改为flex或block。 That solved the issue. 这解决了这个问题。

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

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