Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

md-divider (mat-divider) is not showing in angular material2

I use <md-divider>, like <hr>. I thought it's ok with using like <hr>. However, <md-divider> is sometimes not showing.

I used <md-divider> in the <md-card>, but <md-divider> is not shown. Should I only use <md-divider> in <md-list>?

If someone has the same issue with me, please share your experience to solve this issue.

Here's my code.

<div class="card-height" fxLayoutAlign="center center">
  <md-card fxFlex="30" fxLayout="column">
    <md-card-title>Sign in</md-card-title>
    <form [formGroup]="myForm" (ngSubmit)="onSignin()">
      <md-card-content>
        <div class="form-group">
          <md-input-container>
            <input mdInput placeholder="E-mail" formControlName="email">
            <md-hint>
              <span class="invalid" [hidden]="myForm.controls['email'].pristine || !myForm.controls['email'].errors?.required">Required</span>
              <span class="invalid" [hidden]="myForm.controls['email'].errors?.required || !myForm.controls['email'].errors?.email">This doesn't appear to be a valid email address.</span>
              <span class="invalid" [hidden]="!myForm.controls['email'].errors?.pattern">Email address is not correct.</span>
            </md-hint>
          </md-input-container>
        </div>
        <div class="form-group">
          <md-input-container>
            <input mdInput placeholder="Password" formControlName="password" type="password" fxLayoutAlign="center">
            <md-hint>
              <span class="invalid" [hidden]="myForm.controls['password'].pristine || !myForm.controls['password'].errors?.required">Required</span>
            </md-hint>
          </md-input-container>
        </div>
      </md-card-content>
      <md-card-actions>
        <a [routerLink]="['/forget-password']">Do you forget your password?</a>
        <button md-button color="accent" type="submit">Login</button>
      </md-card-actions>
    </form>

  </md-card>
</div>
like image 263
Mingyu Jeon Avatar asked Feb 27 '17 02:02

Mingyu Jeon


People also ask

How to change color of mat divider?

You need to overrule . mat-divider class styling in your own written CSS and change the border-top-color property. is the default styling by Angular Material. This should be enough to change it (if your CSS gets rendered later than Material's).

What is inset divider?

Inset dividers separate related content, such as sections in a list of contacts or emails in a conversation. Inset dividers should be used in conjunction with anchoring elements such as icons or avatars aligned with the Title Key Line. Example of inset divider.


3 Answers

Update Feb 18

The MatDivider was moved to its own module:

import {MatDividerModule} from '@angular/material/divider';

Outdated Answer

The <md-divider> is part of the MdListModule. If you want to use it, you need to import the MdListModule in your component's module and have at least <md-list></md-list> somewhere in your template. If you're not using lists, importing the whole module for the divider is probably overkill. Just reuse <hr> with your own styles like:

hr {
  display: block;
  margin: 10px 0 10px 0;
  border-top: 1px solid rgba(0, 0, 0, .12);
  width: 100%
}

see Material List Directives

like image 180
Kim Kern Avatar answered Nov 17 '22 21:11

Kim Kern


This helped me.

mat-divider {
    width: 100%;
}

Some details:
It was an Angular component with the following HTML code:

<div class="container">
    <!---some header text-->

    <div class="content">
    <!---some crappy content-->
    </div>

    <mat-divider></mat-divider>   

    <div class = "actions">
        <!--couple of buttons-->
    </div>    
</div>

And here is a CSS file:

.container {
    display: flex;
    flex-direction: column;
    margin: 0 15px;
    align-items: flex-start;
}

.content {
    margin: 0 15px;
}

mat-divider {
    width: 100%;
}

.actions {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    margin: 0px 15px;
}
like image 36
Black Beard Avatar answered Nov 17 '22 19:11

Black Beard


UPDATED: Try mat-divider instead of md-divider

Try this css style.

md-divider {
    border-width: 1px;
    border-style: solid;
}
like image 39
gtzinos Avatar answered Nov 17 '22 21:11

gtzinos