首页 > 解决方案 > 在 Angular 中使用选择器时,如何设置组件显示的大小?

问题描述

我正在使用选择器,<component-selector></component-selector>在页面中显示组件的内容,但它当前显示太大,切断了组件内容的右侧,我试过这个:

<div style="width: 100%; height: 100%; display: block;">
  <component-selector></component-selector>
</div>

因为我希望它填满整个页面,但不显示为大于页面,但这不起作用。如何设置此 div 以使组件占据整个页面,但不会更大/被切断?

标签: javascripthtmlcssangularselector

解决方案


使用两个 div 作为块 Outer 和 Inner One,如果您使用的是选择器,那么您将在选择器 html 代码集中使用一些 html 代码,width:"100%"并在 out div 中使用max-width:"1170px".

所以这样写:

<div style="width:100%"> // in selector html code

<div style="width:1170px">// in your Outer container as you are using

所以最终的代码看起来像这样

<div style="width:1170px; margin: 0px 15px; display:inline-block">
<selector></selector> // here in this html file set width as 100%
</div>

如果您想要解决方案,将在 stackblitz 中编码并与您分享链接,但我知道您可以通过此参考来完成。


推荐阅读