【问题标题】:How to place title in the middle of image in ion slides in Ionic 3?如何在 Ionic 3 的离子幻灯片中将标题放在图像中间?
【发布时间】:2019-02-07 14:23:16
【问题描述】:

这是我的图像和标题的 html 模板,我想在该图像中对齐文本

  <ion-slides   *ngIf="getData.length>0" autoplay="2700" speed="300" class="slideroption" pager="true" loop="true"> 
  <ion-slide *ngFor="let item of getData" (click)="openItem(item)"> 
  <img src="{{item.jetpack_featured_media_url}}" class="new-collection"/> 
      <h4  [innerHTML]="item.title.rendered"></h4>
  </ion-slide>
</ion-slides>

【问题讨论】:

    标签: ionic-framework ionic2 ionic3


    【解决方案1】:

    你可以使用离子卡

    html

    <ion-slides   *ngIf="getData.length>0" autoplay="2700" speed="300" class="slideroption" pager="true" loop="true"> 
       <ion-slide *ngFor="let item of getData" (click)="openItem(item)"> 
         <ion-card class="myCard">
           <img src="{{item.jetpack_featured_media_url}}" class="new-collection"/> 
             <div class="myOverlay">
               <div class="card-title">{{ item.title.rendered }}</div>
               <div class="card-subtitle">{{ some subtitle you like }}</div>
             </div>
          </ion-card>
        </ion-slide>
     </ion-slides>
    

    还有一些样式

    css

    img{
      width:100%;
      height:100%;
    }
    
    .myCard{
      position:relative;
    
    }
    
    .myOverlay{
      width: 100%;
      height: 40%;
      padding-top:5%;
      text-align: center;
      position: absolute;
      z-index: 99;
      bottom: 20%;
      opacity: 0.5;
      color: white;
      font-weight: bold;
      background-color: black;
    }
    

    Working-demo

    【讨论】:

    • 如何为页眉设置样式背景
    • 您能说得更具体些吗?你说的是哪个标题?我提供的解决方案是否满足您的要求?
    • 谢谢,是的,我的文字上有图像,但由于图像无法看到文字,所以我希望标题背景为黑色,并且文字应该可见。谢谢
    • 我已经根据要求以及工作演示编辑了帖子。随意使用 CSS 中的底部、height.padding-top 等属性
    • 喜欢它,谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-07
    • 1970-01-01
    • 2015-05-12
    • 2020-09-22
    • 1970-01-01
    • 2019-01-07
    • 2020-01-21
    相关资源
    最近更新 更多