【问题标题】:Failed to get two rows within a parent row bootstrap 4 and VueJs无法在父行引导程序 4 和 VueJs 中获取两行
【发布时间】:2019-02-10 03:28:00
【问题描述】:

我正在使用 VueJs 和 Boostrap4 创建一个组件,我想在其中使用 bootstrap 提供的类获得与此类似的设计

阅读文档,bootstrap 提供了定制的 h-75 和 h-25 类,我认为这已经足够了,但我没有得到想要的结果

Vue.component('listcontent', {
  template: '<div class="w-100 h-75 bg-info">ds</div>'
})

Vue.component('datashared', {
  template: ' <div class="w-100 h-25 bg-primary">dsadsa</div>'
})


Vue.component('maincomponent', {
  template: `<div class="container h-100" >
        <div class="row h-100">
            <div class="col-md-5 h-100 border">
                <listcontent></listcontent>
                <datashared/></datashared>
            </div>
        </div>
    </div>`
})

new Vue({ el: '#app'});
html,body {
  height: 100% !important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>


<div id="app">
  <maincomponent></maincomponent>
</div>

我做错了什么?我怎样才能达到预期的效果?

【问题讨论】:

    标签: html css vue.js bootstrap-4


    【解决方案1】:

    也将 100% 的高度添加到 id app 元素

    html,
    body,
    #app {
      height: 100% !important;
    }
    

    Vue.component('listcontent', {
      template: '<div class="w-100 h-75 bg-info">ds</div>'
    })
    
    Vue.component('datashared', {
      template: ' <div class="w-100 h-25 bg-primary">dsadsa</div>'
    })
    
    
    Vue.component('maincomponent', {
      template: `<div class="container h-100" >
            <div class="row h-100">
                <div class="col-md-5 h-100 border">
                    <listcontent></listcontent>
                    <datashared/></datashared>
                </div>
            </div>
        </div>`
    })
    
    new Vue({
      el: '#app'
    });
    html,
    body,
    #app {
      height: 100% !important;
    }
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
    <script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
    
    
    <div id="app">
      <maincomponent></maincomponent>
    </div>

    【讨论】:

    • 感谢您的回答,这是否意味着我应该始终将 height: 100% 添加到 vuejs 的根元素中? .在这种情况下,它是#app,但它可能有另一个标识符。因为 w-75 类在不增加宽度的情况下工作:100%
    • 块级元素默认占用浏览器的 100% 宽度,因此 w-75 有效。但是高度不能以这种方式工作。如果要使用 h-75 和 h-25 类,则必须将所有祖先标签的高度设置为 100%。
    • 非常感谢您的回复,效果很好。问候
    • 太棒了!谢谢!!
    【解决方案2】:

    h-100's height:100% 取其父级的高度。由于您没有父母,因此您需要提供固定高度。我用div 包裹了整个 HTML,并设置了 100vh 的高度,即窗口高度。

    由于我不熟悉vue,我曾经将其制作为 HTML。地方 你想要的组件。

    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
    <div style="height:100vh">
    <div class="container h-100">
      <div class="row h-100">
        <div class="col-md-5 h-100 border">
          <div class="w-100 h-75 bg-info">ds</div>
          <div class="w-100 h-25 bg-primary">dsadsa</div>
        </div>
      </div>
    </div>
    </div>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-01
      • 2018-01-29
      • 2017-10-02
      • 2019-01-13
      相关资源
      最近更新 更多