简体   繁体   English

并排显示div的问题

[英]Issue displaying div's side by side

I am trying to create a scrollable div which should show 3 div's side by side. 我正在尝试创建一个可滚动的div,它应并排显示3 div。 Below is my html code, Issue with below code is it is not showing 3 div's side by side instead it is displaying one after other. 下面是我的html代码,下面的代码的问题是并没有显示3 div并排显示。

   <div id="myDIV2" class="mygrid-wrapper-div">
        <h1>This is scrollable div </h1>
        <div class="row row-list">
            <div class="col-xs-4">
                    <div>
                   Test1
                    </div></div>
            <div class="col-xs-4">Test2</div>
            <div class="col-xs-4">
                <div>
                  Test3
                </div></div> 
        </div></div>

css code: CSS代码:

 <style>
        .mygrid-wrapper-div {
            /*border: solid red 5px;*/
            overflow: scroll;
            height: 40%;
        }
    </style>

A div is a "block-level" element. div是“块级”元素。 Block-level elements are 100% of the width of their parent element and displayed on their own line by default. 块级元素是其父元素宽度的100%,默认情况下显示在其自己的行上。

There are several ways to override this layout: 有几种方法可以覆盖此布局:

Set float for the element, which reduces it's width to the width of the content and allows other elements to be on the same line with the floated element. 设置元素的float ,将其宽度减小到内容的宽度,并允许其他元素与float元素在同一行。

Set the width to an amount that leaves left over space for another element to fit on the same line and set the element to be display:inline or display:inline-block . 将宽度设置为留有剩余空间的量,以使另一个元素适合同一行,并将元素设置为display:inlinedisplay:inline-block

Take the element out of the normal document flow by setting its position property to absolute , relative or fixed . 通过将元素的position属性设置为absoluterelativefixed ,将其从常规文档流中fixed

Make the elements flexitems within a flex container. 使元素在flex容器中成为flexitems。

 .mygrid-wrapper-div { overflow: scroll; height: 40%; } .col-xs-4 { border: 1px solid red; float:left; } 
 <div id="myDIV2" class="mygrid-wrapper-div"> <h1>This is scrollable div </h1> <div class="row row-list"> <div class="col-xs-4"> <div ng-controller="myController"> <div ng-repeat="c in chart"> <div google-chart chart="c">test</div> </div></div></div> <div class="col-xs-4">22222222 </div> <div class="col-xs-4"> <div ng-controller="myController"> <div ng-repeat="c1 in chart"> <div google-chart chart="c1">test</div> </div></div></div> </div></div> 

Add the css style: 添加CSS样式:

float:left;

to your divs. 到您的div。

Your plnkr.co example was not loading bootstrap , which is why you were not seeing your divs aligned as expected. 您的plnkr.co示例未加载bootstrap ,这就是为什么您未看到div按预期对齐的原因。 Made the following changes to make it work: 进行了以下更改以使其起作用:

Removed: 删除:

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">

Added: 添加:

<link data-require="bootstrap-css" data-semver="4.0.0-alpha.4" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.4/css/bootstrap.min.css" />
<link data-require="bootstrap@*" data-semver="4.0.5" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" />

Check https://plnkr.co/edit/r6a7lJpNNG2UI1qDbcb6?p=preview 检查https://plnkr.co/edit/r6a7lJpNNG2UI1qDbcb6?p=preview

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

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