对齐中心消息实现css框架

时间:2016-09-05 08:19:31

标签: html css materialize

我正在尝试为用户实施用户通知消息,但我无法将其置于中心位置。这就是我的HTML的样子:

<div class="row">
      <div class="col s12 m4">
        <div id="card-alert" class="card green lighten-5">
          <div class="card-content green-text">
            <p>Successfully added a product!</p>
          </div>
          <button type="button" class="close green-text" data-dismiss="alert" aria-label="Close">
            <span aria-hidden="true">×</span>
          </button>
        </div>
      </div>
    </div>

enter image description here

但是我无法将卡片放在行中间。我还尝试将HTML更改为:

<div class="card-content green-text valign center-block">
  <p>Successfully added a product!</p>
</div>

我也尝试过其他一些东西,但它不起作用。你会如何集中这个?

2 个答案:

答案 0 :(得分:2)

如果您只是想要水平对齐,请添加课程center

<div class="card-content green-text center">

&#13;
&#13;
@import url('https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/css/materialize.min.css');
&#13;
<div class="row">
  <div class="col s12">
    <div id="card-alert" class="card green lighten-5">
      <div class="card-content green-text center">
        <p>Successfully added a product!</p>
      </div>
      <button type="button" class="close green-text" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">×</span>
      </button>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

并为水平和垂直对齐添加以下类。

<div class="card-content green-text center valign-wrapper">
<p class="valign">Successfully added a product!</p>

使用以下样式:

.valign-wrapper {
  height: 200px;
}

.valign {
  width: 100%;
}

&#13;
&#13;
@import url('https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.7/css/materialize.min.css');

.valign-wrapper {
  height: 200px;
}

.valign {
  width: 100%;
}
&#13;
<div class="row">
  <div class="col s12">
    <div id="card-alert" class="card green lighten-5">
      <div class="card-content green-text center valign-wrapper">
        <p class="valign">Successfully added a product!</p>
      </div>
      <button type="button" class="close green-text" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">×</span>
      </button>
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

试试这个!

#card-alert > div {
  margin: auto;
  width: 100px;
}

#card-alert > div {
  margin: auto;
  width: 100px;
}
<div class="row">
      <div class="col s12 m4">
        <div id="card-alert" class="card green lighten-5">
          <div class="card-content green-text">
            <p>Successfully added a product!</p>
          </div>
          <button type="button" class="close green-text" data-dismiss="alert" aria-label="Close">
            <span aria-hidden="true">×</span>
          </button>
        </div>
      </div>
    </div>