html - 使用百分比 (CSS/Bootstrap) 保持容器大小相等的最佳方法

标签 html css twitter-bootstrap

我有一个弹出窗口,在弹出窗口中有 2 个并排的 div。举个例子:

<div id="popup">
    <div id="parentContainer" style="display:inline; width:100%">
    <div id="childContainer" style="display:inline; width:50%">content</div>
    <div id="childContainer" style="display:inline; width:50%">content</div>
    </div>
</div>

大屏幕上的 div 将正常运行并在容器中并排放置。

我遇到的问题是,在手机上,当调整大小时,childContainers 的宽度相对于较小的屏幕变得相对较小,并且不会像在较大的屏幕中那样填充弹出窗口的宽度。

我如何确保如果 div 进入弹出窗口父容器中的新行,它会占用新行的宽度。谢谢

最佳答案

您可以使用 Bootstrap 的列类将内容移动到较小设备上的新行。在下面的示例中,父容器的宽度始终为 100%,具体取决于弹出窗口的宽度。在您设备的像素宽度小于 768 像素之前,子容器将具有 50% 的宽度。低于该像素宽度的设备将导致子容器占据 100% 的宽度,并显示在行中。

<div id="popup">
    <div id="parentContainer" class="col-xs-12">
        <div id="childContainerA" class="col-sm-6 col-xs-12">Content A</div>
        <div id="childContainerB" class="col-sm-6 col-xs-12">Content B</div>
    </div>
</div>

关于html - 使用百分比 (CSS/Bootstrap) 保持容器大小相等的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32358643/

相关文章:

javascript - 如何将 html 文档解析为包含每个节点的行号的 AST?

java.lang.IllegalStateException : Neither BindingResult nor plain target object for bean name 'login' available as request attribute

html - 如何使用填充颜色覆盖 html td?

html - 字段集中的 float 图例在最新版本的 Chrome(版本 55)中无法正确显示?

jquery - 如何在 Jquery 的 .css 部分到达 'this' 元素

html - 文本的背景颜色

css - Bootstrap 相当于 HTML5Boilerplate 的 .visuallyhidden

javascript - 将字符串从数据属性插入数组

twitter-bootstrap - HTML 完整背景图像不适用于 Bootstrap

css - Bootstrap 4 按钮示例 : where does the space between buttons is coming from?