Twitter Bootstrap modal 将 html 内容推送到左侧

2023-06-13前端开发问题
2

本文介绍了Twitter Bootstrap modal 将 html 内容推送到左侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

如果我通过 Twitter Bootstrap 打开一个模态对话框,我注意到它会将页面的所有 html 内容(即,在 container 中)向左推一点,并且然后在关闭后将其恢复正常.但是,只有当浏览器宽度足够大以至于不在移动"(即最小)媒体查询上时才会发生这种情况.最新版本的 FF 和 Chrome 会出现这种情况(尚未测试其他浏览器).

If I open a modal dialog, through Twitter Bootstrap, I've noticed that it pushes all the html content of the page (i.e., in the container) to the left a little bit, and then puts it back to normal after closing itself. However, this only happens if the browser width is large enough to not be on the "mobile" (i.e., smallest) media query. This occurs with the latest versions of FF and Chrome (haven't tested other browsers).

您可以在这里看到问题:http://jsfiddle.net/jxX6A/2/

You can see the problem here: http://jsfiddle.net/jxX6A/2/

注意:您必须增加结果"窗口的宽度,以便它切换到med"或large"媒体查询 css.

我已经根据 Bootstrap 网站上显示的示例设置了页面的 HTML:

I have setup the HTML of the page based upon the examples shown on Bootstrap's site:

<div class="container">
    <div class="page-header">
        <h4>My Heading</h4>
    </div>
    <div id='content'>
        This is some content.
    </div>
    <div class="footer">
        <p>&copy; 2013, me</p>
    </div>
</div>

我猜这不应该发生,但我不确定我做错了什么.

I'm guessing this is not supposed to happen, but I'm not sure what I've done wrong.

这是一个已知错误,有关更多(和最新)信息,请参阅:https://github.com/twbs/bootstrap/issues/9855

This is a known bug, for more (and up-to-date) information, please see: https://github.com/twbs/bootstrap/issues/9855

推荐答案

对于 bootstrap 3.x.x.

For bootstrap 3.x.x.

我找到了一个解决方案,它适用于 100% CSS 而无需 JavaScript.

I have found a solution, that works with 100% CSS and no JavaScript.

诀窍是在 html 内容的滚动条上显示模态滚动条.

The trick is to show the scrollbar for modal over the scrollbar of html content.

CSS:

html {
  overflow: hidden;
  height: 100%;
}
body {
  overflow: auto;
  height: 100%;
}

/* unset bs3 setting */
.modal-open {
 overflow: auto; 
}

这是一个在线示例:http://jsbin.com/oHiPIJi/43/

我在 Windows 7 上对其进行了测试:

I tested it on Windows 7 with:

  • 火狐 27.0
  • 铬 32.0.1700.107 米
  • IE 11 浏览器模式 8、9、10、Edge(桌面)
  • IE 11 浏览器模式 8、9、10、Edge(Windows 手机)

我在 IE 中发现的一个新小问题:

One new little issue I found with IE:

IE 有背景(=body)滚动鼠标滚轮,如果没有更多的东西在前台滚动.

IE has background (=body) scrolling with mouse wheel, if there is nothing more to scroll in the foreground.

小心position:fixed

由于此解决方法的性质,您需要特别注意固定元素.例如,navbar fixed"的填充.需要设置为 html 而不是 body (如何描述 在引导文档中).

Because of the nature of this workaround, you need extra care for fixed elements. For example the padding for "navbar fixed" needs to be set to html and not to body (how it is described in bootstrap doc).

/* only for fixed navbar: 
* extra padding setting not on "body" (like it is described in docs), 
* but on "html" element
* the value used depends on the height of your navbar
*/
html {
  padding-top: 50px;
  padding-bottom: 50px;
}

带包装的替代方案

如果您不喜欢在 html 上设置 overflow:hidden(有些人不喜欢这样,但它有效,有效且 100% 符合标准),您可以将 body 的内容包装在一个额外的 div 中.通过这种方法,您可以像以前一样使用它.

If you do not like setting overflow:hidden on html (some people don't like this, but it works, is valid and 100% standards compliant), you can wrap the content of body in an extra div. You can use it as before by using this approach.

body, html {
  height: 100%;
}
.bodywrapper {
  overflow: auto;
  height: 100%;
}

/* unset bs3 setting */
.modal-open {
 overflow: auto; 
}

/* extra stetting for fixed navbar, see bs3 doc
*/
body {
  padding-top: 50px;
  padding-bottom: 50px;
}

这里是一个例子:http://jsbin.com/oHiPIJi/47/

更新:

Bootstrap 中的问题:

Issues in Bootstrap:

  • #12627
  • #9855

更新 2:仅供参考

在 Bootstrap 3.2.0 中,他们为 modal.js 添加了一个解决方法,该解决方法尝试为 modal.prototype.show() 的每次调用处理 Javascript 问题,Modal.prototype.hide()Modal.prototype.resize().他们为此添加了 7 个(!)新方法.现在,modal.js 中大约 20% 的代码试图处理这个问题.

In Bootstrap 3.2.0 they add a workaround to modal.js that tries to handle the issues with Javascript for every invoke of modal.prototype.show(), Modal.prototype.hide() and Modal.prototype.resize(). They add 7 (!) new methods for that. Now about 20% of code from modal.js tries to handle just that issue.

这篇关于Twitter Bootstrap modal 将 html 内容推送到左侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

Fatal error: Call to a member function fetch_assoc() on a no
业务场景:使用update语句去更新数据库字段。 原因:update接收值不正确。原来代码: $query = "UPDATE student SET date = now() WHERE id = $id";$result = $mysqli-query($query2) or die($mysqli-error); // 问题出现了在这句 $data = $result-fetch_ass...
2024-12-13 前端开发问题
136

layui实现laydate日历控件控制之前日期不可选择
具体实现代码如下: laydate.render({ elem: '#start_time', min:0, //,type: 'date' //默认,可不填}); 只要加一个min参数,就可以控制了。0表示之前的日期不可...
2024-11-29 前端开发问题
133

ajax请求获取json数据并处理的实例代码
ajax请求获取json数据并处理的实例代码 $.ajax({ type: 'GET', url: 'https://localhost:44369/UserInfo/EditUserJson',//请求数据 data: json,//传递数据 //dataType:'json/text',//预计服务器返回的类型 timeout: 3000,//请求超时的时间 //回调函数传参 suc...
2024-11-22 前端开发问题
215

layui 实现实时刷新一个外部的div
主页面上显示了一个合计,在删除和增加的时候需要更改这个总套数的值: //html代码div class="layui-inline layui-show-xs-block" style="margin-left: 10px" id="sumDiv"spanSOP合计:/spanspan${totalNum}/spanspan套/span/div 于是在我们删除这个条数据后,...
2024-11-14 前端开发问题
156

layui 单选框、复选框、下拉菜单不显示问题如何解决?
1. 如果是ajax嵌套了 页面, 请确保 只有最外层的页面引入了layui.css 和 layui.js ,内层页面 切记不要再次引入 2. 具体代码如下 layui.use(['form', 'upload'], function(){ var form = layui.form; form.render(); // 加入这一句});...
2024-11-09 前端开发问题
313

layui laydate日期时间范围,时间默认设定为23:59:59
在Layui中,如果你想设置日期时间选择器(datetime)的默认结束时间为当天的23:59:59,你可以使用如下代码: laydate.render({ elem: '#test10' ,type: 'datetime' ,range: true ,max: '{:date("Y-m-d 23:59:59")}' ,ready: function(date){ $(".layui-laydat...
2024-10-24 前端开发问题
279