gpt4 book ai didi

html - Div 无法在页面上水平居中内容

转载 作者:太空宇宙 更新时间:2023-11-04 01:21:19 24 4
gpt4 key购买 nike

我一直在使用 Materialise,但在这种格式设置上遇到了瓶颈。我似乎无法让它在页面上水平居中。无论我做出什么改变,它都保持左对齐。

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Roboto" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>

<div class="row center">
<div class="col s1 m1">
<i class="material-icons tiny">star</i>
<p style="margin-top: -5px; font-size: .8em; margin-bottom: -10px;">2016</p>
</div>
<div class="col s1 m1">
<i class="material-icons tiny">star</i>
<p style="margin-top: -5px; font-size: .8em; margin-bottom: -10px;">2017</p>
</div>
<div class="col s1 m1">
<i class="material-icons tiny">star</i>
<p style="margin-top: -5px; font-size: .8em; margin-bottom: -10px;">2018</p>
</div>
</div>

View on JSFiddle

最佳答案

您可以使用 col-offset-* 实用程序类从实体化到页面居中

此外,避免使用内联样式,而是使用 CSS 类

.number {
margin-top: -5px;
font-size: .8em;
margin-bottom: -10px;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Roboto" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>



<div class="row center">
<div class="col s1 offset-s5">
<i class="material-icons tiny">star</i>
<p class="number">2016</p>
</div>
<div class="col s1">
<i class="material-icons tiny">star</i>
<p class="number">2017</p>
</div>
<div class="col s1">
<i class="material-icons tiny">star</i>
<p class="number">2018</p>
</div>
</div>

关于html - Div 无法在页面上水平居中内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49018422/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com