[英]Ion-item will not center on the page
I have a problem with trying to center an ion-item as seen below.It's slightly off-center.我在尝试使离子项目居中时遇到问题,如下所示。它略微偏离中心。
I have tried text-align: center
and also change the padding to no padding in ion-content, which doesn't do the trick.我已经尝试过
text-align: center
并将填充更改为在 ion-content 中没有填充,但这并没有起到作用。
I have the following html我有以下 html
<ion-content no padding >
<div style =" text-align: center !important;">
<ion-item style =" text-align: center;"id="projectTitle" color="transparent">
<ion-input placeholder="Project Title" [(ngModel)]="title"></ion-input>
</ion-item>
<div style="text-align: center !important" >
<ion-button color ="transparent">maybe later</ion-button>
</div>
</div>
</ion-content>
And the css和 css
#projectTitle {
margin-top: 300px;
color: white !important;
}
Please help me请帮我
I think the padding of ion-item is the issue.我认为 ion-item 的填充是问题所在。 Add no-padding to ion-item tag, like this:
向 ion-item 标签添加无填充,如下所示:
<ion-content no padding >
<div style =" text-align: center !important;">
<ion-item no-padding style =" text-align: center;"id="projectTitle" color="transparent">
<ion-input placeholder="Project Title"></ion-input>
</ion-item>
<div style="text-align: center !important" >
<ion-button color ="transparent">maybe later</ion-button>
</div>
</div>
</ion-content>
I was able to reproduce your problem on an iOS simulator and indeed, there are 5px offset to the left for list items - but this only holds true for iOS devices.我能够在 iOS 模拟器上重现您的问题,实际上,列表项左侧有 5px 偏移 - 但这仅适用于 iOS 设备。 Web browsers and Android devices do not have this offset.
Web 浏览器和 Android 设备没有这个偏移量。
Although, I was not able to pinpoint the exact location of where these 5px offset are introduced, I have a potential workaround for you.虽然,我无法确定引入这些 5px 偏移的确切位置,但我为您提供了一个潜在的解决方法。 You can just add this snippet to the (S)CSS of your component and should be fine:
您可以将此代码段添加到组件的 (S)CSS 中,应该没问题:
ion-list.list-ios>ion-item>* { transform: translate3d( -5px, 0px, 0px); // Fix x-offset for iOS, while preserving z reset of:host }
If you are planning to use ion-sliding-item elements just change the first line to:如果您打算使用 ion-sliding-item 元素,只需将第一行更改为:
ion-list.list-ios>ion-item-sliding>ion-item>* {
See this answer https://stackoverflow.com/a/56078763/3538289看到这个答案https://stackoverflow.com/a/56078763/3538289
Specifically, the following snippet alters the default ionic ion-item
shadow CSS that adding 16px padding to the left, which pushes content to the right (off-center).具体来说,下面的代码片段改变了默认的 ionic
ion-item
shadow CSS,它向左侧添加了 16px 的内边距,从而将内容推送到右侧(偏离中心)。
ion-item {
--padding-start: 0px !important;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.