【问题标题】:Vuetify, how to center content and strech a columnVuetify,如何使内容居中并拉伸列
【发布时间】:2020-12-31 02:56:40
【问题描述】:

我正在尝试使用 2 列的布局,我希望它们具有相同的高度,并且里面的内容应该垂直居中。

这是我在 vuetify 中的代码

<div id="app">
  <v-app>
    <v-row align="center">
      <v-col cols=6 style="background-color: #FF5000;"  align="center">
           <v-btn class="m">Column 1</v-btn>
      </v-col>
      <v-col cols=6 style="background-color: #5fc3c7;">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
      </v-col>
    </v-row>
  </v-app>
</div>

我已尝试将&lt;v-row align="center"&gt; 更改为&lt;v-row align="stretch"&gt;,该列按我的意愿拉伸,但内容不在中心。..

任何帮助都会很棒

【问题讨论】:

    标签: html css vue.js vuetify.js


    【解决方案1】:

    可以在v-col中添加一些css styles,使用flex实现vertical middle

    <v-col cols=6 style="background-color: #FF5000; display: flex; align-items: center; justify-content: center"  align="center">
    
    

    https://codepen.io/chengtingsen/pen/abNGxLd

    【讨论】:

      【解决方案2】:

      正如Tingsen Cheng 提到的,您可以在v-col 中添加弹性样式以实现垂直居中。此外,从 Vuetify 2.3.10 开始,您可以使用他们的 flex helper,它为您提供实用程序类来轻松控制您的布局。

      所以不要使用内联style,你可以使用类似这样的东西:class="d-flex justify-center align-center"

      <v-row align="stretch">
        <v-col 
          cols="6"
          style="background-color: #FF5000;"
          class="d-flex justify-center align-center"
        >
          <v-btn>...</v-btn>
        </v-col>
        <v-col cols="6" style="background-color: #5fc3c7;">...</v-col>
      </v-row>
      

      这是codesandbox 的演示。

      【讨论】:

      • 谢谢!按预期工作!我以为 v-col 默认是 flex 但实际上不是,它是一个块,不像 v-row,所以当我尝试 justify-center 时它不起作用,使用 d-flex 类就可以了!!
      猜你喜欢
      • 2018-11-19
      • 1970-01-01
      • 2018-07-30
      • 1970-01-01
      • 2011-03-16
      • 2013-07-12
      • 2014-11-17
      • 2012-08-11
      • 1970-01-01
      相关资源
      最近更新 更多