html - 使用 Bootstrap 的表格列宽

标签 html bootstrap-4

这是我在 StackOverflow 中的第一个问题,因为这是我第一次找不到可以帮助我解决问题的答案。
我正在尝试为带有 Bootstrap 的菜单制作一个表格。我希望早餐、午餐和晚餐栏的宽度各为 30%,碳水化合物、脂肪和蛋白质栏的宽度为 10%,但我做不到。
我通读了 the documentation实际上发现了一个非常相似的问题here .但是,我仍然无法使其工作。 我把我的代码 here in CodePen这样您就可以看到我所看到的。

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<table class="table table-bordered">
  <thead>
    <tr class="m-0">
      <th class="w-10">#</th>
      <th class="w-30">Breakfast</th>
      <th class="w-30">Lunch</th>
      <th class="w-30">Dinner</th>
    </tr>
  </thead>
  <tbody>
    <tr class="m-0">
      <th scope="row" class="w-10">Carbohydrates</th>
      <td class="w-30">-
      </td>
      <td class="w-30">
        -
      </td>
      <td class="w-30">-
      </td>
    </tr>
    <tr class="m-0">
      <th scope="row" class="w-10">Fat</th>
      <td class="w-30">-
      </td>
      <td class="w-30">
        -
      </td>
      <td class="w-30">-
      </td>
    </tr>
    <tr class="m-0">
      <th scope="row" class="w-10">Proteins</th>
      <td class="w-30">-
      </td>
      <td class="w-30">
        -
      </td>
      <td class="w-30">-
      </td>
    </tr>
  </tbody>
</table>

谁能帮我找出我遗漏的东西?我刚刚自学编码大约 3 个月,并于上周开始使用 bootstrap,所以我希望这不是很明显的事情。
提前致谢!

最佳答案

你需要提供CSS规则

table .w-10 { width:10%; }
table .w-30 { width:30%; }

请注意,Bootstrap 确实带有 some predefined width classes ,但仅限于 25% 的倍数。

关于html - 使用 Bootstrap 的表格列宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48607947/

相关文章:

html - Bootstrap 网格以最小尺寸中断

css - 如何使溢出元素不增加 flexbox 的高度?

javascript - 在函数中引导数据切换模态内容

html - 宽度 : 50% and flex: 50% in a CSS flexbox? 之间的差异

javascript - HtmlAudioElement 音频时间延迟

android - Android 浏览器支持多少 HTML5?

html - 我可以在同一个 html 文件中同时使用 bootstrap 3 和 bootstrap 4 来处理网页中不同的 div 吗?如果可以,该怎么做

html - 使用 Zurb Foundation 将文本覆盖添加到面板和图像?

php - 针对 wordpress 背景的另一个图像

html - CSS:不需要 div 额外边距