如何在我的背景中添加一个 id?

How to add an id to my background?

我用ionic 3。 如何为我的背景添加一个id?

ion-content {
        background-image: url('../assets/imgs/back.png');
        background-size: 100%;
        background-repeat: no-repeat;   }

So I think you're a bit confused, in CSS classes and IDs both act as selectors and can both use the same CSS properties.这意味着通常不需要同时拥有一个对象。拥有一个 ID 和一个 class(或多个 class)并没有错,只是通常没有必要。

看这个例子:https://codepen.io/samandalso/pen/zaPpve

在其中我们在同一个 div 上使用一个 ID 和一个 class,但是您可以轻松地将所有 CSS 规则移动到一个或另一个并获得同样的结果。最后一个选择器是一个子选择器,它表示 div 是具有 class "ion-content" 的父级的子级,在所有四个边上填充 100px 并使颜色变为红色。有帮助吗?

/* Individual selectors */
#myID {
  background-size: cover;
  width: 100vw;
  height: 100vh;
}

.ion-content {
  background: url(http://via.placeholder.com/100x100) center center;
  text-align: center;
}

/* Child selector */

.ion-content div {
  color: red;
  padding: 100px;
}