简体   繁体   English

CSS如何在Ionic中将项目居中

[英]CSS How to center an item in Ionic

I am using Ionic3, and have the following: 我正在使用Ionic3,并且具有以下功能:

在此处输入图片说明

I would like to center align the ion-card. 我想使离子卡居中对齐。

html html

  <div class="contracted-content">

  <ion-card class="job-card">

    ...

  </ion-card>

  <div class="person-job">
    <ion-row>

      ...

    </ion-row>
  </div>

 </div>

scss 脚本

.contracted-content {
    max-width: 369px;
    align-content: center;    
}

As you can see, I set the max width to 369px, so that the image does not distort. 如您所见,我将最大宽度设置为369px,以使图像不会变形。 Now, when the browsers width gets increased beyond the 369px, I would like to center the div (the align-content: center; has no affect). 现在,当浏览器的宽度增加到超过369px时,我想将div居中( align-content: center;没有影响)。

Any advise appreciated. 任何建议表示赞赏。

Try using margin: 0 auto; 尝试使用margin: 0 auto; to center your element 使您的元素居中

try this: 尝试这个:

DEMO HERE 此处演示

CSS 的CSS

.align-center{
display: inline-block;
position: relative;
left: 50%;
webkit-transform: translateX(-50%);
transform: translateX(-50%);
}

HTML 的HTML

<ion-card class="job-card align-center">
 ...
</ion-card>

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

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