【问题标题】:Modal pushing conent to the left模态向左推送内容
【发布时间】:2018-10-12 10:57:16
【问题描述】:

我查看了其他问题和答案,但似乎无法解决此问题。

我的页面中有一个模式,它正在将页面的内容向左移动一点。

我做了一个示例小提琴,它显然不完全相同的代码,但问题是一样的。 当您单击 TEST 时,会显示模态,并推送一些内容。

    <div class="modal fade" id="modalContactos" tabindex="-1" role="dialog" aria-labelledby="modalContactos1" aria-hidden="true">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="modalContactos1">Contactos</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>

<nav class="navbar navbar-expand-md navbar-light fixed-top bg-light">
<ul class="navbar-nav mr-1">

            <a class="navbar-brand head" id="contatoshead" data-toggle="modal" data-target="#modalContactos" data-placement="bottom" data-trigger="hover" title="Contatos" href="#">
              TEST
            </a>

        </ul>
</nav>

<div class="container-fluid">

<div class="row" id="sidebartest1">
<p>
Test
</p>
</div>

</div>


<main class="col-sm-9 ml-sm-auto col-md-10 pt-3" role="main">
<p>
tEST
</p>
</main>

https://jsfiddle.net/x38boerf/

知道如何解决这个问题吗?

提前致谢。

【问题讨论】:

    标签: javascript html css bootstrap-4 bootstrap-modal


    【解决方案1】:

    代码中的主块有一个值为 auto 的 margin-left 属性。将其设置为 0,它应该会阻止它移动。

    澄清一下,这是由应用于 main 的“ml-sm-auto”类引起的

    【讨论】:

    • 谢谢,这会停止将左侧推向左侧,但现在它会压缩它,仅将右侧推入。我尝试添加一个固定的边距,但没有奏效。跨度>
    • 在你的 CSS 中将 body 宽度设置为 100%
    • 是的,我明白了!我有这个“宽度:计算(100vw - 17px);”在 html 上,我记得我把它用来解决一些我想我后来以其他方式解决的问题,现在它只是对我不利。导航栏上有一些内容仍然会被推送,但这是因为“mx-auto”。关于如何确保内容居中而不使用自动的任何提示?顺便说一句,感谢您引导我朝着正确的方向前进!
    • 如果你想让文本居中,你可以使用text-align: center。如果您希望主块居中,则需要将宽度设置为小于 100% 并使用margin: 0 auto。 margin 属性是 margin top 和 bottom 0 以及 margin left 和 margin right auto 的简写。这将强制元素进入页面中间。
    【解决方案2】:
    please add below code in css.
    
    .ml-sm-auto, .mx-sm-auto {
        margin-left: 0 !important;
    }
    

    【讨论】:

    • 与其他答案相同的问题。现在它不向左推,而是向左推,压缩内容。同样使用此解决方案,我的主要内容“高于”我的侧边栏,但我显然可以通过添加一些填充来解决这个问题。尽管如此,上述问题仍然存在。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-16
    • 1970-01-01
    • 1970-01-01
    • 2013-10-20
    • 2019-08-14
    • 1970-01-01
    • 2021-12-12
    相关资源
    最近更新 更多