How come there isn't any spacing between my Angular Material cards in Angular 8?

I am currently studying Angular 8 and need some help figuring out why there is no space between these cards. The image below indicates a red line where the space should be.

https://i.sstatic.net/riMYF.png

Below is my Component html:

<mat-card class="mat-space-bottom">
  <mat-card-header><mat-card-title>Book Search API</mat-card-title></mat-card-header>
  <form [formGroup]="newContact" class="form-container">

    <mat-form-field>
      <input type="text" matInput placeholder="Title"  formControlName="title" #box (keyup.enter)="getTitle(box.value)"> <p>{{value}}</p>
    </mat-form-field>

    <mat-form-field>
      <input type="text" matInput placeholder="Author" formControlName="author" #box (keyup.enter)="getAuthor(box.value)"> <p>{{value}}</p>
    </mat-form-field>

    <mat-form-field>
      <input type="text" matInput placeholder="Genre" formControlName="genre" #box (keyup.enter)="getGenre(box.value)"> <p>{{value}}</p>
    </mat-form-field>

    <mat-form-field>
      <input type="text" matInput placeholder="Price" formControlName="price" #box (keyup.enter)="getPrice(box.value)"> <p>{{value}}</p>
    </mat-form-field>

  </form>

</mat-card>


<mat-card class="mat-space-bottom" *ngFor="let phone of bookItems">

  <mat-card-header >
    <!-- <div mat-card-avatar class="firstLetter">{{phone.title | slice:0:1 | uppercase}}</div> -->
    <mat-card-title>{{phone.title | titlecase}}</mat-card-title>
    <mat-card-subtitle>{{phone.description}}</mat-card-subtitle>
    <mat-card-subtitle>{{phone.author}}</mat-card-subtitle>
    <mat-card-subtitle>{{phone.genre}}</mat-card-subtitle>
    <mat-card-subtitle>{{phone.publish_date}}</mat-card-subtitle>
    <mat-card-subtitle>{{phone.price}}</mat-card-subtitle>

  </mat-card-header>
  <!--
  <mat-card-actions>
    <a title="Edit Contact" routerLink="/contact/{{phone.id}}">
      <i class="material-icons">edit</i>
    </a>
    <a class="delete" title="Delete Contact" (click)="delete(phone, phone.id)">
      <i class="material-icons">close</i>
    </a>
  </mat-card-actions>
  </div> -->
</mat-card>

And this is my scss for styling:

mat-card {
  display: flex;
}

mat-card-header {
  width: 100%;
  display: flex;
  align-items: center;
}

mat-card-actions {
  margin-left: auto;
}

mat-card-subtitle {
  margin-bottom: 0;
}

mat-card:not(:last-child) {
  margin-bottom: 15px;
}

mat-card-actions {
  padding-top: 0;
}

.firstLetter {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 22px;
}

mat-card:nth-child(1n) .firstLetter {
  background: #2e6da4;
}

mat-card:nth-child(2n) .firstLetter {
  background: #4cae4c;
}

mat-card:nth-child(3n) .firstLetter {
  background: #46b8da;
}

mat-card:nth-child(4n) .firstLetter {
  background: #eea236;
}

mat-card:nth-child(5n) .firstLetter {
  background: #d43f3a;
}

.delete i {
  cursor: pointer;
  color: #d43f3a;
}

.mat-space-bottom {
  margin-bottom: 10px;
  ...
}

Answer №1

Issue not reproducible on stackblitz... it's possible something is missing;

Please review working example on stackblitz here

The HTML/CSS you provided was used, here is the relevant ts file:

import {Component} from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';

@Component({
  selector: 'card-fancy-example',
  templateUrl: 'card-fancy-example.html',
  styleUrls: ['card-fancy-example.css'],
})
export class CardFancyExample {
  bookItems:any[];
  newContact = new FormGroup({
    title: new FormControl(''),
    author: new FormControl(''),
    genre: new FormControl(''),
    price: new FormControl(''),
  });

  constructor(){
    this.bookItems = [
      { title:'test title' ,description:'test descr ' ,author:'test author' ,genre:'test1 genre' ,publish_date:'test date' ,price:'test price' }
      ,{ title:'test title' ,description:'test descr ' ,author:'test author' ,genre:'test1 genre' ,publish_date:'test date' ,price:'test price' }
      ,{ title:'test title' ,description:'test descr ' ,author:'test author' ,genre:'test1 genre' ,publish_date:'test date' ,price:'test price' }
      ,{ title:'test title' ,description:'test descr ' ,author:'test author' ,genre:'test1 genre' ,publish_date:'test date' ,price:'test price' }
      ,{ title:'test title' ,description:'test descr ' ,author:'test author' ,genre:'test1 genre' ,publish_date:'test date' ,price:'test price' }
    ];
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

real-time mat-progress-bar constantly updating

Is it possible to have the progress bar updated in real-time without having to reload the page every time? <mat-progress-bar *ngIf="row.stage === 'importing_in_progress'" class="exchange-files__progress-bar" mode=&quo ...

Paths of least resistance: Absolute URLs for assets in CSS

What could be causing the absolute path for this asset (the font) not to work while the relative path does? <body> hello friend </body> <style type="text/css"> @font-face { font-family: 'Gilroy'; /* src: ur ...

Incorrect behavior of responsive background images

For the first time, I am working on a school project that requires me to create a responsive website. I am following the "mobile first" approach. On stackoverflow, I came across a helpful way of making background images responsive: background-image: url(. ...

Troubleshooting problem with div width in Outlook causing table cell padding issue for curved corners on another div

This question has significantly evolved following additional testing I am using a table layout similar to this: <table> <tr> <td></td> <td style="padding:10px 3%;"> <div border="2px solid #000000;"> ...

When implementing TypeScript in Next.js, the web worker is not loading correctly

For my project, I am utilizing Next.js which utilizes Webpack 5 for bundling. I came across this webworkers guide that suggested using the following syntax to load web workers: new Worker(new URL('./worker.js', import.meta.url)); However, when I ...

Switching downlink to top link when scrolling downwards

I have a downward scrolling link on my homepage that moves the page down when clicked by the user. However, I am struggling to make it change to a "back to top" link as soon as the user scrolls 10 pixels from the top. Additionally, I am having trouble with ...

Creating a Typescript union array that utilizes a string enum for defining key names

Can we shorten this statement using string enum to restrict keys: Array<{ [enum.example1]: Example } | { [enum.example2]: Example } | ...> // or equivalent ({ [enum.example1]: Example } | { [enum.example2]: Example } | ...)[]; We can make it more c ...

The color of my Navbar remains stationary despite implementing Javascript for scroll effects

I am having trouble with the Javascript portion of my code, which I copied from a tutorial. The Navbar is not changing color when scrolled, and I'm not sure if the issue lies with the Javascript, the CSS, or if I need to add 'scrolled' to th ...

Mastering the Art of Crafting an Effortless Slide Showcase

I have created a carousel that works fine except for one issue: when I reach the last image or go back from the first image, I want the image to be displayed. For example, when you click the right arrow after reaching the last image, it should show the fir ...

Tips for optimizing Jquery selectors to streamline recurring functions

I have 9 "service node" divs in my HTML code, each containing a hidden div and a button that triggers the rotation of the button by 45 degrees and reveals the hidden div. The challenge I am facing is that I have been using repetitive functions for each ser ...

What is the best way to place text side by side with an image?

How can I align text below a picture like this? https://i.stack.imgur.com/WcNRa.jpg Here is the code snippet: https://jsfiddle.net/vzjj9eLy/ HTML: <span class="test"> <img src="http://cdn.sstatic.net/Sites/stackoverflow/img/<a href="/cd ...

Encountering Type Error in Angular 2

Here is the Angular 2 code snippet I am working with: <ion-grid *ngFor="let item of menuData; let i = index;" ng-init="getAllItemToGrid()"> <img src="{{'assets/Products/'+menuData[i].image}}" ng-click="onLogin()" width="100%"> ...

Swap out a Dropdown Menu for a text box in a flexible design layout

Is it possible to switch out a Dropdown Menu with a text box in a search form? The textbox needs to match the size of the Dropdown Menu being replaced. Here is the code for the form: <form action="#"> <input type="text" class ...

Issue with Angular 2 in Visual Studio 2013: Pressing Ctrl+K+D causes formatting to change to lowercase

Please note that while this issue is not directly related to Angular2, anyone who uses Angular2 with Visual Studio 2013 may be able to help. Whenever I use the key combination Ctrl + K + D in Visual Studio 2013, it changes HTML or Angular2 directives/mark ...

Avoiding the collision of two absolutely positioned elements

I have a website mockup where I've placed two elements - a logo and a form on the screen. Both are positioned absolutely, but on smaller screens, they end up overlapping (or coming very close to it). Since you can't add margin-top to elements wit ...

Having difficulty transforming ".jsx" to ".tsx" in a Next.js application while working with "getStaticProps"

My application utilizes the Printifull API and performs well with .jsx using the code snippet below: import axios from "axios"; export default function ApiTest(props) { console.log(props); return( <></> ( } export async ...

Responsive Bootstrap column with a fixed-width card

My Bootstrap-card is currently not adjusting its width properly. I want the card to occupy the full width of the column it's in. Below is a snippet of my code and a screenshot showing the current width along with the desired width indicated by a blue ...

Angular 2 is struggling to locate the file with the name 'Set'

Currently, I am in the process of upgrading my project from angular2 beta15 to rc4. However, when I try to compile, I encounter the following error: path/node_modules/@angular/common/src/directives/ng_class.d.ts(81,35): error TS2304: Cannot find name &a ...

Is it possible to use jQuery to search an unordered list by simply pressing a key on the keyboard?

I have a list of countries displayed as an unordered list inside a table column. I would like to implement keyboard search functionality for quicker navigation within the list. <ul class="country-search"> <li id="1">Country 1</li> ...

Adjusting the Angular ngsw-worker.js file

Is it possible to customize the ngsw-worker.js file in my Angular14 project? I am also wondering how I can rename the ngsw-worker.js to something like ngsw.js. This specific file is located within the app node-modules directory. ...