html - 覆盖 Bootstrap 3 CSS 样式

标签 html css twitter-bootstrap twitter-bootstrap-3

我有这样的风格:

.form-style{
   margin: 50px auto;/* also tried margin: 50px auto !important; */
   /* other styles */
 }

我在我的 div 元素中使用它是这样的:

<div class="row">
<div id="myDiv" class="form-style col-md-6 col-md-offset-3">
<p>This is a text.</p>
</div>
</div>

如果我不使用 form-style 我的 div 会出现在中心。但是我想使用 form-style 并且当我使用它时, form-style 的 margin 属性将阻止 Bootstrap col-md-offset-3 使我的 div 居中。我怎样才能覆盖父边距,以便它没有为我的 div 设置?

如果我从 form-style 中删除 margin 它工作正常。但我无法删除边距,因为它用于我元素的其他部分。

最佳答案

不确定你为什么想要这样的东西,因为它看起来很hack,但你的问题是你的元素是 float 的,这就是边距自动不起作用的原因,所以你需要删除 float 以使其工作。 (但这不是一个好主意,因为它会使 Bootstrap 表现得很奇怪)

.form-style {
  margin: 50px auto!important;
  float: none!important;
  /* other styles */
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class=container>
  <div class="row">
    <div id="myDiv" class="form-style col-xs-6 col-xs-offset-3">
      <p>This is a text.</p>
    </div>
  </div>
</div>

关于html - 覆盖 Bootstrap 3 CSS 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48040743/

相关文章:

html - 如何获得列表项显示 block ?

php - 2 列布局缺少内容

javascript - 使用 window.open() 或带有 _target 属性的超链接,是否可以强制链接在新窗口而不是新选项卡中打开?

javascript - 如何创建 Windows 资源管理器大缩略图样式列表?

php - 我将如何更改我从数据库中检索的每个元素的 CSS 类?

javascript - 单击该 div 中的按钮后隐藏 div

javascript - 如何在 Javascript 乒乓球游戏中正确地偏转球?

html - 前端 : How to (properly) achieve this masking effect with css

css - Bootstrap 4 卡 : remove blank space

html - Bootstrap 3 - 两列布局 - 摆脱占位符