简体   繁体   English

如何将 s router-outlet 的内容居中

[英]how do I center the content of s router-outlet

I'm trying to horizontally center the content of a router-outlet in angular;我正在尝试以角度水平居中路由器插座的内容; However all the regular tricks I am using are not working;但是,我使用的所有常规技巧都不起作用; after searching google for all the usual suspects i tried:在谷歌搜索我尝试过的所有常见嫌疑人之后:

  • display: block;显示:块; margin: 0 auto;保证金:0自动;
  • placing it in a div and using the above code将它放在一个 div 中并使用上面的代码
  • trying to select the component that will be there depending on the route even though may or may not be there尝试根据路线选择将在那里的组件,即使可能存在也可能不存在
  • I can center it by adding padding to the body but it will then not be centered on all screen sizes我可以通过向主体添加填充来将其居中,但它不会在所有屏幕尺寸上居中
  • I centered a img above the component just to see if display: block;我将一个 img 放在组件上方,只是为了查看是否显示:块; margin: 0 auto;保证金:0自动; works at all, it works on the img tag完全有效,它适用于 img 标签
  • used the depricated 'center' tag使用了 depricated 'center' 标签
  • used text-align: center;使用文本对齐:居中;

this is an angular 2+ project这是一个有角度的 2+ 项目

html: HTML:

<img src="https://i.ibb.co/6R6pcMm/MRG-Updated-Logo.jpg" />   <!--centered-->
<router-outlet></router-outlet>                               <!--not_centered-->

css: CSS:

img {
  display: block;
  margin: 0 auto;
}

router-outlet {
  display: block;
  margin: 0 auto;
}

HTML HTML

<div class="center-me"><router-outlet></router-outlet></div> 

CSS CSS

.center-me{
  display: block;
  margin: 0 auto;
}

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

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