【问题标题】:Where does the spacing in Bootstrap button examples come from?Bootstrap 按钮示例中的间距从何而来?
【发布时间】:2021-08-30 21:42:44
【问题描述】:

Bootstrap 5 button examples 中,按钮之间有一个空格。我不确定这个空间是在哪里定义的,也没有在 devtools 中找到任何边距:

Devtools Screenshot

这个空间是从哪里来的?

编辑1

在我的示例中(使用 tailwind),尽管使用了 inline-block,但仍缺少空间。有没有办法操纵间距,或者我错过了什么。

Devtools Screenshot of my inline-block buttons

转载示例:

https://codepen.io/jjoharrer/pen/ZEyQWyo

【问题讨论】:

  • display: inline-block; 进入btn 类做“把戏”
  • @SimoneRossaini 谢谢,但在我的测试中(没有引导程序),即使使用inline-block(参见Edit1),这个空间也不存在。
  • 您尝试在不使用引导程序的情况下复制空间代码?
  • @SimoneRossaini 我目前正在学习顺风,并尝试创建自己的(引导导向;)风格指南。我知道这似乎是一个相当基本的问题,但我无法弄清楚为什么我的示例中缺少空格。
  • 发布您的代码。

标签: css twitter-bootstrap tailwind-css


【解决方案1】:

正如您在引导示例中看到的那样,所有输入都是输入而不是一个按钮,如果您只是复制另一个按钮而没有那个按钮,那么就像您的示例一样。您需要像 bootstrap 一样重新创建边距类:

.button {
  background-color: green;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/1.1.2/tailwind.min.css">
<div>
  <div>
    <button id="" class="button no-underline text-center rounded inline-block active button-primary py-1 px-2 mr-2">Primary</button>
    <!--v-if--><button id="" class="button no-underline text-center rounded inline-block active button-secondary py-1 px-2 mr-2">Secondary</button>
    <!--v-if--><button id="" class="button no-underline text-center rounded inline-block active button-info py-1 px-2 mr-2">Info</button>
    <!--v-if--><button id="" class="button no-underline text-center rounded inline-block active button-success py-1 px-2 mr-2">Success</button>
    <!--v-if--><button id="" class="button no-underline text-center rounded inline-block active button-warning py-1 px-2 mr-2">Warning</button>
    <!--v-if--><button id="" class="button no-underline text-center rounded inline-block active button-danger py-1 px-2 mr-2">Danger</button>
    <!--v-if-->
  </div>
</div>

在这种情况下,我使用 mr-2(右边距 2)


正如您在此处看到的,如果您向下(按回车键)使用代码,所有工作都按预期工作,因此按钮将有一个空格,否则将没有空格

.button {
  background-color: green;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/1.1.2/tailwind.min.css">
<div>
  <div>
    <button class="button no-underline text-center rounded inline-block active button-primary py-1 px-2 ">Primary</button>
    <button class="button no-underline text-center rounded inline-block active button-primary py-1 px-2 ">Primary</button>
    <button class="button no-underline text-center rounded inline-block active button-primary py-1 px-2 ">Primary</button><button class="button no-underline text-center rounded inline-block active button-primary py-1 px-2 ">Primary</button>
  </div>
</div>

【讨论】:

  • 这并没有回答他们的文档中关于块之间的空间来自哪里的问题。
  • 是的,我知道 mr-2 实用程序类,但正如 alex 评论的那样,我没有看到引导文档中使用了这样的实用程序类。我不完全理解你对As you can see in the bootstrap example are all input instead of one button的意思
  • 啊,源代码中的中断(或空格)有所不同。不知何故,在我的 vuejs 组件中删除了中断。谢谢!
猜你喜欢
  • 1970-01-01
  • 2022-11-24
  • 2019-11-08
  • 2019-04-16
  • 1970-01-01
  • 2012-11-26
  • 1970-01-01
  • 1970-01-01
  • 2018-11-01
相关资源
最近更新 更多