简体   繁体   English

HTML 表格通过 CSS 渲染图像无法正常工作

[英]HTML table rendering images via CSS not working properly

I have an HTML table which renders images (arrows) in the table cells.我有一个 HTML 表,它在表格单元格中呈现图像(箭头)。 The images are displayed depending in some logic in an Angular component.图像的显示取决于 Angular 组件中的某些逻辑。 The columns which are displaying the images are located next to each other.显示图像的列彼此相邻。 When on the same row the two images need to be displayed, the formatting in the table goes wrong (both images are displayed in the first column, and the remaining cell of the table are shifted to the left).当需要在同一行显示两个图像时,表格中的格式出错(两个图像都显示在第一列,表格的剩余单元格向左移动)。 when only one image is displayed, then there is no problem.当只显示一张图像时,则没有问题。 I suspect the CSS of the images is the cause of the problem.我怀疑图像的 CSS 是问题的原因。

    <tbody>
    <tr *ngFor="let taPatternDto of taPatternInstrumentResponseDto; index as i">
      <td style="width: 20px" scope="row">{{ i + 1 }}</td>
      <td>{{ taPatternDto.taPatternInstrumentId }}</td>
      <td>{{ taPatternDto.symbol }}</td>
      <td style="width: 180px">{{ taPatternDto.name }}</td>
      <td style="width: 40px">{{ taPatternDto.liquid }}</td>
      <td [class]="getFlagClass(taPatternDto.countryCode)" style="width: 14px"></td>
      <td style="width: 180px">{{ taPatternDto.exchangeName }}</td>
      <td>{{taPatternDto.sector }}</td>

      <!- two-images next to each other -->
      <td [class]="getWatchArrowCssClass(taPatternDto.watch)"></td>
      <td [class]="getBuySellArrowCssClass(taPatternDto.buySell)"></td>

      <td style="width: 180px">{{ taPatternDto.pattern }}</td>
      <td style="width: 30px"><img src="assets/img/chart.png"  height="30" width="30" (click)="displayChart(content, taPatternDto);"/></td>
    </tr>
    </tbody>

Correct rendering正确渲染

在此处输入图像描述

Incorrect rendering不正确的渲染

在此处输入图像描述

CSS CSS

.green-arrow {
  background-size:contain;
  background-position:50%;
  background-repeat:no-repeat;
  position:relative;
  display:inline-block;
  width:1.33333333em;
  line-height:1em;
   background-image:url(../../assets/img/arrows/green_arrow_up_16.png);
 }

.red-arrow {
  background-size:contain;
  background-position:50%;
  background-repeat:no-repeat;
  position:relative;
  display:inline-block;
  width:1.33333333em;
  line-height:1em;
  background-image:url(../../assets/img/arrows/red_arrow_down_16.png);
}

.orange-arrow-up {
  background-size:contain;
  background-position:50%;
  background-repeat:no-repeat;
  position:relative;
  display:inline-block;
  width:1.33333333em;
  line-height:1em;
  background-image:url(../../assets/img/arrows/orange_arrow_up_16.png);
}

.orange-arrow-down {
  background-size:contain;
  background-position:50%;
  background-repeat:no-repeat;
  position:relative;
  display:inline-block;
  width:1.33333333em;
  line-height:1em;
  background-image:url(../../assets/img/arrows/orange_arrow_down_16.png);
}

I think this is exactly where you are having the problem:我认为这正是您遇到问题的地方:

      <!- two-images next to each other -->
      <td [class]="getWatchArrowCssClass(taPatternDto.watch)"></td>
      <td [class]="getBuySellArrowCssClass(taPatternDto.buySell)"></td>

You gain an extra <td></td> tag when you have both images showing.当您同时显示两个图像时,您将获得一个额外的<td></td>标记。 What I suggest doing is instead:我建议做的是:

      <!- two-images next to each other -->
      <td>
        <span [class]="getWatchArrowCssClass(taPatternDto.watch)"></span>
        <span [class]="getBuySellArrowCssClass(taPatternDto.buySell)"></span>
      </td>

The tags used is totally up to you.使用的标签完全取决于您。 I just used <span> for the example.我只是用<span>作为例子。

Also, you might want to remove some information regarding your images if you have signed some NDA with a client to prevent information about your app from getting shared globally.此外,如果您已与客户签署了一些 NDA 以防止有关您的应用程序的信息在全球范围内共享,您可能希望删除有关您的图像的一些信息。 You can use skitch to blur out certain parts of your image.您可以使用skitch来模糊图像的某些部分。

Best of luck!祝你好运!

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

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