Centralize input inside a div using materialize

1

I have a form with an input inside, I would like to leave it centralized. I can do this in the custom.css I have. But as I'm using Materoalize, I'd like to know if you can do this through it.

<form class="col s12">
  <div class="row">
    <div class="input-field col s12">
      <input placeholder="Digite seu nome" id="name" type="text">
      <label for="name" class="active">Nome</label>
    </div>
    <div class="input-field col s12">
      <input placeholder="Digite seu telefone" id="phone" type="tel">
      <label for="phone" class="active">Telefone</label>
    </div>
    <div class="input-field col s12">
      <input placeholder="Digite seu e-mail" id="email" type="email">
      <label for="email" class="active">E-mail</label>
    </div>

  </div>
</form>
    
asked by anonymous 13.05.2018 / 20:13

2 answers

1

Try to put like this in your html: form class="col s6 offset-s3"

Note: Sent by cell phone

    
13.05.2018 / 20:27
3

If Materialize has a special class to align text to the center, the class calls center-align here has the documentation link

However, only with him will you not be able to align everything. In inputs I used center-align and it worked fine, already for the label I had to customize some classes.

Already to align the whole form in the middle of the screen the grid has to be aligned as @Leandro spoke. 3 - 6 - 3 or 5 - 2 - 5 if you want narrower, or in equal parts like I did col s4 offset-s4

See how the result was.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Page Title</title>
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
<style>
    
.input-field label:not(.label-icon).active {
    -webkit-transform-origin: center;
    transform-origin: center;
}
.input-field.col label {
    left: 0;
}
.input-field label {
    text-align: center;
    width: 100%;
}
 
</style>
</head>
<body>
    
<form class="col s12">
    <div class="row">
        <div class="input-field col s4 offset-s4">
        <input class="center-align" placeholder="Digite seu nome" id="name" type="text">
        <label for="name" class="active">Nome</label>
        </div>
        <div class="input-field col s4 offset-s4">
        <input class="center-align" placeholder="Digite seu telefone" id="phone" type="tel">
        <label for="phone" class="active">Telefone</label>
        </div>
        <div class="input-field col s4 offset-s4">
        <input class="center-align" placeholder="Digite seu e-mail" id="email" type="email">
        <label for="email" class="active">E-mail</label>
        </div>
    </div>
</form>

    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>
</body>
</html>
    
13.05.2018 / 21:13