简体   繁体   English

移动单选按钮的标签以放置在单选按钮上方

[英]Moving the label of a radiobutton to be placed above the radiobutton

So I have a radiobutton with a label.所以我有一个带标签的单选按钮。 The problem is that the label and buttons are in the same line (row).问题是标签和按钮在同一行(行)。 I want my buttons to be underneath the label!我希望我的按钮位于标签下方! Here is my code:这是我的代码:

<v-radio-group row v-model="voltage" @click="consoles" label="SELECT 
VOLTAGE:">
              <v-radio
                v-for="n in radioNames"
                :key="n"
                :label="n"
                :value="n"
              ></v-radio>
              </v-radio-group>
              <v-radio-group row v-model="dependency">

It currently lookslike this:它目前看起来像这样: 在此处输入图片说明

As you can see the label and buttons are in the same line.如您所见,标签和按钮在同一行中。 How do I move to label to be above the buttons (top left. Like "S" should be placed exactly on top of the left button)?如何移动到按钮上方的标签(左上角。像“S”应该正好放在左按钮的顶部)?

Using p for label使用p作为标签

As far as I can see from Vuetify API there is no option to set the label as column and the v-radio as row.据我从Vuetify API看到的,没有选项可以将label设置为column ,将v-radio为行。 A simple solution would be add the label as a separate element from the v-radio-group :一个简单的解决方案是将标签作为独立于v-radio-group元素添加:

<p>SELECT VOLTAGE:</p>
<v-radio-group row v-model="voltage" @click="consoles">
  <v-radio v-for="n in radioNames" :key="n" :label="n" :value="n" />
</v-radio-group>

Using v-layout使用v-layout

Based on @SnakeyHips answer there is a simple way to set the v-radio elements in a row.根据@SnakeyHips 的回答,有一种简单的方法可以连续设置v-radio元素。 Use a <v-layout align-start row> to wrap only the radio buttons in a row:使用<v-layout align-start row>仅将radio按钮包裹在一行中:

<v-radio-group label="SELECT VOLTAGE:" v-model="row">
  <v-layout align-start row>
   <v-radio v-for="n in radioNames" :key="n" :label="n" :value="n" />
  </v-layout>
</v-radio-group>

Here is an example of both solutions.这是两种解决方案的示例

If you want the labels of each radio button to be above the button then you could handle all the layout manually yourself without the v-for loop like so:如果您希望每个单选按钮的标签位于按钮上方,那么您可以自己手动处理所有布局,而无需 v-for 循环,如下所示:

<v-radio-group v-model="radioGroup">
  <v-layout row wrap>
  <v-flex column>
    <p>Label 1</p>
    <v-radio key=1 value=1>
      </v-radio>
    </v-flex>
  <v-flex column>
    <p>Label 2</p>
    <v-radio key=2 value=2>
      </v-radio>
    </v-flex>
  <v-flex column>
    <p>Label 3</p>
    <v-radio key=3 value=3>
      </v-radio>
    </v-flex>
  </v-layout>
</v-radio-group>

Currently, v-radio-group in row mode is a flexbox.目前,行模式下的 v-radio-group 是一个 flexbox。 So you can give the legend element a width of 100% and this will force a line break.因此,您可以为图例元素设置 100% 的宽度,这将强制换行。 eg例如

.v-input--radio-group__input legend{
  width: 100%
}

     

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

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