简体   繁体   English

如何使用css在html中对齐png图像

[英]How to align png image in html using css

参考图片2 参考图片 1

Hi, once look at the reference image one it is having one small one image on every box.嗨,一旦查看参考图像,它就会在每个盒子上都有一个小的图像。

->But if I try to move the image to the left side with the help of margin-left (33rem) it is not appearing on the screen as shown in reference image 2 ->但是如果我尝试在 margin-left (33rem) 的帮助下将图像移动到左侧,它不会出现在屏幕上,如参考图像 2 所示

->And look at the border-bottom line in every box that is in the loop so in every box it is showing but i don't want that border-bottom line at 6th line I want only 5 border-bottom lines in every box -> 并查看循环中每个框中的边框底线,因此在它显示的每个框中,但我不希望第 6 行出现边框底线我只希望每个框中有 5 条边框底线

Html html

<mat-card class="mat mr-4 ml-5 p-3" fxLayout="column" fxFlex>

  <div fxLayout="row wrap" fxFlex fxLayoutGap="20px">
    <ng-container *ngFor="let item of items">
    <!-- customer  -->

    <div  fxFlex="calc(33.3% - 20px)" class="m-1 pt-3">
      <div fxLayout  class="overview-style">
        <div [ngStyle]="{'background-color':item.color, 'border':item.border}" class="overview-cart">
          <div class="ml-5 mt-4 heading-text">{{item?.title}}</div>

        <img class="pl-5" src="assets/icons/img.png" width="80px">
      </div>
      </div>
      <div  class="content pl-3">
        <div *ngFor="let subModule of item?.submodules; let index=index">
          <div fxLayoutAlign="space-between center" class="pb-1 main-line border-bottom pt-2">
            {{subModule?.title}}
            <mat-icon *ngIf="index === 0"class="arrow-icon">arrow_right_alt</mat-icon>
            <span class="mr-4 value-color">{{subModule?.value}}</span>
          </div>
        </div>
      </div>
      <!-- </ng-container> -->
    </div>
</ng-container>
  </div>

</mat-card>

Css css

.overview-cart {
  position: relative;
  width: calc(100%);
  // background-color: #5f7dff;
  overflow: hidden;

  &:after {
    content: "";
    position: absolute;
    right: -100px;
    top: 0;
    border-width: 153px;
    border-style: solid;
    border-color: transparent;
    border-top-color: #fff;
    z-index: 99;
    // transform: rotate(0deg);
  }
}

.overview-style {
  width: 100%;
  justify-content: center;
  height: 30%;
  // border: 1px solid #5f7dff;
}

.heading-text {
  // margin-left: 15%;
  font-size: 18px;
  font-weight: normal;
  color: #fff;
  // margin-top: 1.5rem;
}

img {
  // width: 90px;
  margin-left: 33rem;
  height: min-content;
  margin-top: -35px;
}

.mat {
  height: auto;
}

.line {
  // padding-bottom: 5px;
  font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
  font-size: 14px;
}

.main-line {
  // font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
  font-size: 14px;
  color: #0b4983;
}

.arrow-icon {
  line-height: 0.8;
  color: #0b4983;
  margin-right: 70%;
}

.value-color {
  color: #065a3d;
  text-align: end;
}

.content {
  background-color: #f7f7f9;
}

Ts Ts

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-home-stream',
  templateUrl: './home-stream.component.html',
  styleUrls: ['./home-stream.component.scss']
})
export class HomeStreamComponent implements OnInit {

  navStyle = 'font-size: 1.2rem; color: cornflowerblue;';

  constructor() { }


  items: any[]= [
    {
      id : 1,
      color: '#5f7dff',
      border: '1px solid #5f7dff',
      width: '100%',
      title: 'Customer',
      submodules: [
      { title:'members' ,value: '1000'},
      { title:'non-members', value: '250'},
      { title:'traders', value: '200'},
      { title:'members', value: '40'},
      { title: '-', value:''},
      { title: '-', value:''}
      ]
    },
    {
      id: 2,
      color: '#00ce86',
      border: '1px solid #00ce86',
      width: '100%',
      title: 'Loans',
      submodules: [
        { title:'crop-loan-admin' ,value: '1000'},
      { title:'members', value: '250'},
      { title:'traders', value: '200'},
      { title:'employees', value: '40'},
      { title: '-', value:''},
      { title: '-', value:''}
      ]
    },
    {
      id: 3,
      color: '#ec4b53',
      border: '1px solid #ec4b53',
      width: '100%',
      title: 'Insurance',
      submodules:  [
        { title:'members' ,value: '1000'},
        { title:'non-members', value: '250'},
        { title:'traders', value: '200'},
        { title:'members', value: '40'},
        { title: '-', value:''},
        { title: '-', value:''}
        ]
    },

    {
      id: 4,
      color: '#24a8f2',
      border: '1px solid #24a8f2',
      width: '100%',
      title: 'Inventory',
      submodules:  [
        { title:'members' ,value: '1000'},
        { title:'non-members', value: '250'},
        { title:'traders', value: '200'},
        { title:'members', value: '40'},
        { title: '-', value:''},
        { title: '-', value:''}
        ]
    },
    {
      id: 5,
      color: '#ff7eb7',
      border: '1px solid #ff7eb7',
      width: '100%',
      title: 'Accounts',
      submodules:  [
        { title:'members' ,value: '1000'},
        { title:'non-members', value: '250'},
        { title:'traders', value: '200'},
        { title:'members', value: '40'},
        { title: '-', value:''},
        { title: '-', value:''}
        ]
    },
    {
      id: 6,
      color: '#44e2e3',
      border: '1px solid #44e2e3',
      width: '100%',
      title: 'Masters',
      submodules:  [
        { title:'members' ,value: '1000'},
        { title:'non-members', value: '250'},
        { title:'traders', value: '200'},
        { title:'members', value: '40'},
        { title: '-', value:''},
        { title: '-', value:''}
        ]
    },
  ]
  ngOnInit() {
  }

}

Demo 演示

  1. I cant fully reproduce your code to look like yours.我无法完全重现您的代码以使其看起来像您的代码。 In order to solve the position, just fix the margin-left value为了解决位置,只需固定 margin-left 值
img {
  margin-left: 4rem;
  height: min-content;
  margin-top: -35px;
}
  1. Use <div *ngFor="let subModule of item?.submodules; index as i"> and *ngIf="i < 5" could help you do the if statement使用<div *ngFor="let subModule of item?.submodules; index as i">*ngIf="i < 5"可以帮助您执行 if 语句

     <div class="content pl-3"> <div *ngFor="let subModule of item?.submodules; index as i"> <div *ngIf="i < 5" fxLayoutAlign="space-between center" class="pb-1 main-line border-bottom pt-2" > {{ subModule?.title }} <span class="mr-4 value-color">{{ subModule?.value }}</span> </div> </div> </div>

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

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