简体   繁体   English

子类上的className影响父元素

[英]className on children affects parent element

Im building a card object and I want it to have the className .card which is defined in css like this: 我正在构建卡对象,我希望它具有在CSS中定义的className .card ,如下所示:

.card img{position:absolute; width:150px; height:160px}

which mean I want only the images inside my div to cover each other and not the div's themselves. 这意味着我只希望div内的图像相互覆盖,而不希望div本身。 Every time a create 2 or more cards, they cover each other as if they had the position: absolute property. 每当创建2张或更多张卡时,它们就会相互覆盖,就好像它们具有position: absolute属性一样。

My JavaScript Code: 我的JavaScript代码:

  this.add = function()
  {
    console.log("add");
    this.container.appendChild(this.backImg);
    this.container.appendChild(this.frontImg);
    this.container.className = "card";
    document.body.appendChild(this.container);
  };
};

var card1 = new Card(1);
card1.add();

通过以下方式将相同宽度和高度的图像应用于容器卡:

.card { position: relative; width:150px; height:160px }

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

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