I am experimenting with Material Design Web 1.0 having the following code:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8"/>
    <meta http-equiv="Content-Security-Policy" content="default-src 'self' https://fonts.gstatic.com; script-src 'unsafe-inline' https://unpkg.com; style-src 'unsafe-inline' https://unpkg.com https://fonts.googleapis.com"/>
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Test</title>

    <link href="https://unpkg.com/[email protected]/dist/material-components-web.css" rel="stylesheet"/>
    <script src="https://unpkg.com/[email protected]/dist/material-components-web.js"></script>
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"/>
    <style>
      .my-card-content 
       {
        padding: 16px;
       }
    </style>
  </head>
  <body>
    <div class="mdc-card my-card-content">

      <div class="mdc-layout-grid">
        <div class="mdc-layout-grid__inner">
          <div class="mdc-layout-grid__cell"><label class="mdc-floating-label" for="username">Username</label></div>
          <div class="mdc-layout-grid__cell">
            <div class="mdc-text-field">
              <input type="text" id="username" class="mdc-text-field__input" required  tabindex="0">
              <div class="mdc-line-ripple"></div>
            </div>
          </div>
        </div>
        <div class="mdc-layout-grid__inner">
          <div class="mdc-layout-grid__cell"><label class="mdc-floating-label" for="password">Password</label></div>
          <div class="mdc-layout-grid__cell">
            <div class="mdc-text-field">
              <input type="password" id="password" class="mdc-text-field__input" required  minlength="8"  tabindex="0">
              <div class="mdc-line-ripple"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </body>
</html> 

What I really wanted is to have the Username/Password labels/fields centered within the card, but it looks like this at the moment:

enter image description here

I find it strange that the username/password labels hang left outside of the card ...

How to change the layout to be as I expected? Is there a way to do this without the grid layout?

1 Answers

1
Ludo On

You could try to remove (on your label element) :

class="mdc-floating-label"

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8"/>
    <meta http-equiv="Content-Security-Policy" content="default-src 'self' https://fonts.gstatic.com; script-src 'unsafe-inline' https://unpkg.com; style-src 'unsafe-inline' https://unpkg.com https://fonts.googleapis.com"/>
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Test</title>

    <link href="https://unpkg.com/[email protected]/dist/material-components-web.css" rel="stylesheet"/>
    <script src="https://unpkg.com/[email protected]/dist/material-components-web.js"></script>
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"/>
    <style>
      .my-card-content 
       {
        padding: 16px;
       }
    </style>
  </head>
  <body>
    <div class="mdc-card my-card-content">

      <div class="mdc-layout-grid">
        <div class="mdc-layout-grid__inner">
          <div class="mdc-layout-grid__cell"><label for="username">Username</label></div>
          <div class="mdc-layout-grid__cell">
            <div class="mdc-text-field">
              <input type="text" id="username" class="mdc-text-field__input" required  tabindex="0">
              <div class="mdc-line-ripple"></div>
            </div>
          </div>
        </div>
        <div class="mdc-layout-grid__inner">
          <div class="mdc-layout-grid__cell"><label for="password">Password</label></div>
          <div class="mdc-layout-grid__cell">
            <div class="mdc-text-field">
              <input type="password" id="password" class="mdc-text-field__input" required  minlength="8"  tabindex="0">
              <div class="mdc-line-ripple"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </body>
</html>