html - 对齐 Material 设计图标上方的文本(使用 materializecss)

标签 html css material-design materialize

我目前正在使用 materializecss 框架并拉入一个图标并将其放在文本旁边。我需要用 css 将图标上方 中间的文本对齐,但我目前所拥有的似乎不起作用。

<table class="centered">
    <thead>
        <th class="align-text"><i class="material-icons small">timer</i>Time</th>
        <th>Another header</th>
        <th>And another header</th>
    </thead>
</table>

目前我的 css 文件:

.align-text {
     display: inline-block;
     text-align: center;
     vertical-align: top;
}

但是,文本仍然位于图标的右侧。

这是我最终要达到的结果。

enter image description here

最佳答案

已更新:这是您需要的东西^_^ DEMO

<!DOCTYPE html>
<html>

<head>
  <!--Import Google Icon Font-->
  <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <!--Import materialize.css-->
  <link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection" />
  <style>
    th {
      display: inline-block;
    }
    .align-text {
      display: inline-block;
      text-align: center;
      vertical-align: top;
    }
    span {
      display: block;
    }
  </style>
  <!--Let browser know website is optimized for mobile-->
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>

<body>

  <table class="centered">
    <thead>
      <th class="align-text"><span>Time</span><i class="material-icons small">timer</i>
      </th>
      <th class="align-text"><span>Time</span><i class="material-icons small">timer</i>
      </th>
      <th class="align-text"><span>Time</span><i class="material-icons small">timer</i>
      </th>
    </thead>
  </table>

  <!--Import jQuery before materialize.js-->
  <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
  <script type="text/javascript" src="js/materialize.min.js"></script>
</body>

</html>

关于html - 对齐 Material 设计图标上方的文本(使用 materializecss),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35678753/

相关文章:

javascript - jQuery + CSS cursor mousedown + Chrome = 不工作

html - 如何垂直对齐图标字体

javascript - href ="#"在页面 url 末尾附加#

html - 为所需星号添加跨度时 Bootstrap 输入组插件对齐问题

html - 如何在@media 和跨浏览器中水平居中 div 类?

css - 单选按钮和复选框在 Material 设计中不起作用

javascript - 使用 HTML5/Canvas/JavaScript 等复制 BBC iPlayer 旋转效果

html - 当窗口调整大小时,我的导航菜单消失了

android - 在 float 操作按钮中创建菜单

android - 了解菜单图标颜色的来源