简体   繁体   English

在响应式设计中并排保持div

[英]Maintaining divs side-by-side in responsive design

As a beginner user of Bootstrap's grid system, I need to keep two divs side-by-side using a float:left regardless of device. 作为Bootstrap网格系统的初学者,无论设备如何,我都需要使用float:left并排保持两个div。 This is so that a jQuery animation moves a parent div right and left to bring either div into view. 这样,jQuery动画就可以左右移动父div ,以使任一div都可见。 How to structure the HTML of the green boxes to achieve this effect? 如何构造绿色框的HTML以实现此效果? Or it purely a css media query matter? 还是纯粹是CSS媒体查询很重要?

在此处输入图片说明

Disregard the blue box. 忽略蓝色框。

This is what I have so far: 这是我到目前为止的内容:

<div class="container">
    <div class="col-xs-12 col-md-7 view">
        <div id="panelviewer">  
            <div class="row">
                <div class="col-xs-12 col-md-6 panel1">one</div>
                <div class="col-xs-12 col-md-6 panel2">two</div>
            </div>
        </div>
    </div>
</div>

Jsfiddle 的jsfiddle

There are other ways to keep the div s side by side and achieve what you need: 还有其他方法可以使div并排并实现您所需要的:

#panelviewer .row {white-space:nowrap;}
.panel1       {display:inline-block;float:none;background:#aaa;}
.panel2       {display:inline-block;float:none;background:#eee;}

Demo http://jsfiddle.net/7HcQ8/3/ 演示 http://jsfiddle.net/7HcQ8/3/

No matter what unless you implicitly specify in a media query and your cells are too wide to fit in mobile it will force onto two lines. 除非您在媒体查询中隐式指定,并且单元格太宽而无法容纳移动设备,否则它将强制执行两行操作。 In this case when it hits the mobile breakpoint decrease the size of the content so it will fit. 在这种情况下,当碰到移动断点时,请减小内容的大小,以使其适合。 Place a unique class on those DIVs such as class="sizeSmaller" and this might help out: 在这些DIV上放置一个唯一的类,例如class =“ sizeSmaller”,这可能会有所帮助:

   @media (max-width: 768px) {
    .sizeSmaller {
   height:50%;
    width:50%;
  }

}

Adjust the width of the media query to suit your neds. 调整媒体查询的宽度以适合您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM