css - 使 ionic ionic 元素具有透明背景

标签 css ionic2

有没有办法制作 ionic 2的背景<ion-item>透明吗?

我试过这个 CSS,但它没有使元素透明:

.list .item, .item-content .item-inner .item-block .item-ios
{
  background: transparent !important;
}

添加代码

我的 HTML 看起来像这样:

<ion-content class="pu-my-plans-background">

  <div *ngIf="hasPlans">
    <ion-list no-lines class="pu-item-list">
      <!--<ion-item-group reorder="true" (ionItemReorder)="reorderItems($event)">-->
        <ion-item-sliding *ngFor="let plan of plans; let i = index" >
          <ion-item class="pu-section-list-item pu-my-plans-item" (click)="editPlan(plan.id, plan.rev, plan.title, i)">
            {{ plan.title }}
            <br>
            <span class="pu-my-plans-plan-date">{{ plan.updated}}</span>
            <button *ngIf="plan.important" ion-button clear item-right>
              <ion-icon name="ios-alert-outline"></ion-icon>
            </button>
          </ion-item>
          <ion-item-options side="right">
            <button ion-button color="danger" (click)="deletePlan(plan.id, plan.rev)">
              <ion-icon name="delete"></ion-icon>
              Delete
            </button>
          </ion-item-options>
        </ion-item-sliding>
      <!--</ion-item-group>-->
    </ion-list>
  </div>

</ion-content>

我的 CSS 是这样的:

page-my-plans {

}

.pu-my-plans-plus-circle {
  display: block;
  //border: 2px solid white;
  background-color: $pu-orange;
  border-radius: 50%;
  height: 38px;
  width: 38px;
}

.pu-my-plans-plus-circle span {
  font-size: 38px;
  font-weight: 100;
  color: white;
  position: absolute;
  top: -7px;
  left: 8.5px;
}
.pu-plan-addButton {
  font-size: 30px;
  margin-right: 14px;
  margin-top:-2px;
}


.pu-section-list-item{
  color: white;
  background-color: black;
  font-weight:$pu-item-font-weight;
  font-size:$pu-item-font-size;
  padding-left:20px;
  padding-right:0px;
}
.item{
  background: transparent !important
}
// THEMING CSS
// ===========
//
.pu-my-plans-background {
  background-image: url("../assets/img/my_plan_bg@2x.png");
  background-size: cover !important;
}
.pu-my-plans-item {
  border-style:solid;
  border-bottom-width: 2px;
  border-bottom-color: $pu-orange;
}
.pu-my-plans-plan-date {
  color: $pu-orange;
  font-size: 11px;
  font-weight: 200;
}

我已经尝试了所有我能想到的 ionic 2 元素样式组合,但我能得到的最好结果是在 ion-item 后面获得白色背景。 ion-content 有图像背景,但我无法通过 ion-item 看到它。

最佳答案

这是 Ionic 4 中的一个解决方案:

HTML:

<ion-list class="bg-transparent">
    <ion-item color="none" lines="none">
        Some random text
    </ion-item>
    <ion-item color="none" lines="none">
        Some random text
    </ion-item>
</ion-list>

CSS:

.bg-transparent {
  background: transparent;
}

需要注意的重要事项:

  • 通过应用类并添加 CSS 将主列表的背景颜色设置为透明,如图所示。
  • 为每个 ion-item 添加 color="none" 属性。
  • lines="none" 删除每个 ion-item 下的行

应该可以了!

关于css - 使 ionic ionic 元素具有透明背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41892006/

相关文章:

jquery - 选择自定义属性设置样式

javascript - ionic 2 在应该寻找 app.js 的时候却寻找 app.ts

css - 样式禁用 ionic 选择

html - 当网页按比例缩小时,如何使图像堆叠在一起?

javascript - D3 树动态更新节点颜色

xcode - 将 Ionic 2 与 XCode 结合使用 - 更新更改

javascript - 带有对象的 ionic 搜索栏不会显示任何内容

angular - Ionic 3 导入自定义组件

html - Bradley Hand ITC Bold 字体未在 mozilla 和 chrome 中显示

javascript - 滚动过去后将 Div 粘在顶部