html - 如何删除 Bootstrap 3 链接之间的间距?

标签 html css ruby-on-rails twitter-bootstrap-3

我正在尝试为应用程序的 Web View 重新创建 4 个“按钮”,这些按钮是静态的并且仅在移动 View 中处于固定位置。这个想法是它们占据了屏幕 100% 的宽度,使它看起来像一个原生应用。

但是,每个元素之间似乎都有间距,我不知道如何摆脱它。如果我将框的宽度设置为 24%,它们将适合一行但有间距。如果它是 25%,那么我在一行中得到 3 个,在下面的单独一行中得到第 4 个。 enter image description here

CSS:

.mobileShow {
  display: none;
}



/* Smartphone Portrait and Landscape */
@media only screen and (min-device-width: 320px) and (max-device-width: 480px) {
  .mobileShow {
    display: inline-block;
    width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
    margin: 0 0 0 0;
    padding: 0px;
  }
}

#mobileButton {
  width: 25%;
  border-radius: 0px;
  background-color: antiquewhite;
  padding: 10px 0 !important; 
  border: 0px;
  margin: 0 !important;
}

代码是 RoR,但本质上是吐出正常链接。 代码:

  <div class="mobileShow">
      <%= link_to "Box 1", "#", class: "btn btn-default", id: "mobileButton"%>
      <%= link_to "Box 2", "#", class: "btn btn-default", id: "mobileButton" %>
      <%= link_to "Box 3", "#", class: "btn btn-default", id: "mobileButton" %>
      <%= link_to "Box 4", "#", class: "btn btn-default", id: "mobileButton" %>
  </div>

最佳答案

您需要在 CSS 中添加 box-sizing 属性。
由于您使用了 padding: 10px; 属性,它提供了额外的元素,强制其他对象自动调整。使用 box-sizing: border-box; 将帮助您修复它。

#mobileButton {
  width: 25%;
  border-radius: 0px;
  background-color: antiquewhite;
  padding: 10px 0 !important; 
  border: 0px;
  margin: 0 !important;
  box-sizing: border-box; /*here*/
}

你也可以在这里阅读:
https://www.w3schools.com/cssref/css3_pr_box-sizing.asp

关于html - 如何删除 Bootstrap 3 链接之间的间距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59121996/

相关文章:

html - Firefox 中的圆 Angular : space between border and background

ruby-on-rails - 如何在 Memcache 中缓存天气(Nokogiri::XML::NodeSet 对象)?

html - 表单操作相对 URL

javascript - ngSubmit 没有触发 Controller 中的功能

javascript - 扩展文本的动态 Div 长度

css - 在表格单元格 html5 中定义对象

android - 将 activity 中的 minHeight 设置为 webView

javascript - jQuery左右按钮滚动

ruby-on-rails - 月/日的慢性解析

ruby-on-rails - 如何使用 Rails 通过 Web 服务以 JSON 格式公开数据?