我正在尝试为用户实施用户通知消息,但我无法将其置于中心位置。这就是我的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>
但是我无法将卡片放在行中间。我还尝试将HTML更改为:
<div class="card-content green-text valign center-block">
<p>Successfully added a product!</p>
</div>
我也尝试过其他一些东西,但它不起作用。你会如何集中这个?
答案 0 :(得分:2)
如果您只是想要水平对齐,请添加课程center
。
<div class="card-content green-text center">
@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;
并为水平和垂直对齐添加以下类。
<div class="card-content green-text center valign-wrapper">
<p class="valign">Successfully added a product!</p>
使用以下样式:
.valign-wrapper {
height: 200px;
}
.valign {
width: 100%;
}
@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;
答案 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>