cssangularnebular

Can't aling horizontally items in Angular


I have 4 item in a div that are show vertically, but I want them align horizontally. I don't know what I'm missing but I'm unable to do it

This is the HTML

<div class="teachers-box" *ngFor="let user of usuarios">
    <nb-user
      class="teacher-box"
      size="large"
      name="{{ user.name }}"
      color="#cccac8"
      onlyPicture
    >
    </nb-user>
  </div>

This is the .ts where I get the data

usuarios = [
    { name: 'Gabriel A' },
    { name: 'Maximiliano B' },
    { name: 'Chavez C' },
    { name: 'Juan Pablo' },
  ]

This are the scss styles

.teachers-box {
  display: inline-block;
}

.teacher-box {
  display: inline-block;
}

I noticed that the item width is taking the whole screen, but I don't know how to remove it enter image description here


Solution

  • You can create a div that will wrapper both the div and nb-user

    Something like:

      <div class="wrapper">
        <div class="teachers-box" *ngFor="let user of usuarios">
            <nb-user
              class="teacher-box"
              size="large"
              name="{{ user.name }}"
              color="#cccac8"
              onlyPicture
            >
            </nb-user>
        </div>
     </div>
    

    And the style:

    .wrapper {
      display: flex;
    }
    

    And then you can delete the display inline-block from other classes