How to align text with the center of the div with Materialize?

Asked

Viewed 377 times

2

I have a div with a text and an image:

div sem destacamento div com área destacada em azul

This div has a block of text that should be aligned with the center. To make the alignment, I used the class .valign-wrapper, that worked perfectly with the image. However, when applying the class, it only has effect on the image, ignoring the paragraph attached beside.

How can I align this block of text?

Structure of the DOM

<div class="valign-wrapper">
  <div class="col s12 l6">
      <div class="col s12 l5 center-align">
        <p><img class="responsive-img circle" src="http://lorempixel.com/200/200/" alt="avatar"/></p>
      </div>
      <div class="col s12 l7 center-align valign-wrapper">
        <p class="user">
          <span>
            <small class="message">Bem vindo,</small><br/> <strong id="user-name">Fulano da Silva</strong>
          </span> <br/>
          <span class="phone">(51) 9 9999 - 9999 </span><br/>
          <span class="mail">[email protected]</span>
        </p>
      </div>
    </div>
</div>

CSS used

.avatar p.user{
  color: #455a64;
  line-height: 102%;
  margin-left: 0.2em;
}

span.phone, span.mail, small.message{
  font-size: 12px;
  word-wrap: break-word;
}

strong#user-name{
  font-size: 16px;
}

.avatar img{
  width: auto;
  max-width: 7em;
  height: auto;
}
  • which version of materialize?

  • I’m using version 1.0.0

1 answer

1


Guy basically you’re using the class in the wrong div, and class valign-wrapper that’s it

inserir a descrição da imagem aqui

I mean it’s a container flex, with align-items: center. But only the direct children of this container will line up in the center, and you put the class on the grandmother

inserir a descrição da imagem aqui

See that fixing it all lines up

inserir a descrição da imagem aqui

Code of the image above

<!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/1.0.0/css/materialize.min.css">

  <!-- Compiled and minified JavaScript -->
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <style>
  
  .avatar p.user{
  color: #455a64;
  line-height: 102%;
  margin-left: 0.2em;
}

span.phone, span.mail, small.message{
  font-size: 12px;
  word-wrap: break-word;
}

strong#user-name{
  font-size: 16px;
}

.avatar img{
  width: auto;
  max-width: 7em;
  height: auto;
}
  
</style>
</head>
<body>
    <div class="row">

        <div class="col s6">

            <div class="valign-wrapper">
                <div class="col s12 l6 valign-wrapper">
                    <div class="col s12 l5 center-align">
                      <p><img class="responsive-img circle" src="http://lorempixel.com/200/200/" alt="avatar"/></p>
                    </div>
                    <div class="col s12 l7 center-align valign-wrapper">
                      <p class="user">
                        <span>
                          <small class="message">Bem vindo,</small><br/> <strong id="user-name">Fulano da Silva</strong>
                        </span> <br/>
                        <span class="phone">(51) 9 9999 - 9999 </span><br/>
                        <span class="mail">[email protected]</span>
                      </p>
                    </div>
                  </div>
              </div>
        </div>
        <div class="col s6">6-columns (one-half)</div>
      </div>

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.