代码之家  ›  专栏  ›  技术社区  ›  MarcoLe

鞋带-IMG Mantain徽章响应灵敏

  •  2
  • MarcoLe  · 技术社区  · 8 年前

    我需要一个IMG内的徽章- 独立于窗口大小 -到目前为止,我的HTML代码中有以下代码(顺便说一句,我使用的是角度框架——但框架应该是不相关的):

    .icon-container {
      display: inline-block;
      position: relative;
    }
    
    troop-level-badge {
      position: absolute;
      bottom: 2px;
      left: 2px;
    }
    `
    <div class="container row" *ngIf="img">
      <div class="col-md-1">
        <div class="icon-container">
          <img class="rounded" [src]="img" width="40" height="auto">
          <span class="badge badge-dark troop-level-badge">6</span>
        </div>
      </div>
    </div>`

    到目前为止,结果如下(如预期): expected Version

    但当我调整窗口大小时,徽章会从div. 有人知道即使调整窗口大小,我也可以在img中包含徽章吗?

    1 回复  |  直到 8 年前
        1
  •  1
  •   Sebastian Brosch Navjyot    8 年前

    你的 troop-level-badge 规则无效。有一点遗漏了。所以替换 部队级徽章 具有 .troop-level-badge 它应该像下面这样工作。要在右侧显示徽章,您需要设置 right:2px; 而不是 left:2px; :

    .icon-container {
      display:inline-block;
      position:relative;
    }
    .troop-level-badge {
      bottom:2px;
      position:absolute;
      right:2px;
    }
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
    
    <div class="container row" *ngIf="img">
      <div class="col-md-1">
        <div class="icon-container">
          <img class="rounded" src="https://placehold.it/100x100" >
          <span class="badge badge-dark troop-level-badge">6</span>
        </div>
        <div class="icon-container">
          <img class="rounded" src="https://placehold.it/75x75" >
          <span class="badge badge-dark troop-level-badge">6</span>
        </div>
        <div class="icon-container">
          <img class="rounded" src="https://placehold.it/50x50" >
          <span class="badge badge-dark troop-level-badge">6</span>
        </div>
      </div>
    </div>