You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vue Form Generator中如何实现单选按钮的横向排列?

How to Align Radio Button Options Horizontally (Inline) in vue-form-generator

Great question! Since you’re already using Bootstrap-style classes like col-md-*, we can leverage that to get your radio buttons inline easily. Here are two straightforward solutions:

vue-form-generator lets you pass classes directly to the radio button containers via the inputClasses property. Just add this line to your gender field configuration:

{
  type: "radios",
  label: "Gender",
  model: "gender",
  values: [
    "Male",
    "Female",
    "Other"
  ],
  styleClasses:'col-md-3',
  inputClasses: 'form-check-inline' // Add this line
}

Bootstrap’s form-check-inline class overrides the default block-level display of each radio option, making them sit side by side instead of stacking vertically.

Solution 2: Custom CSS (If you aren’t using Bootstrap)

If Bootstrap isn’t part of your project, add this custom CSS to your component’s <style> section:

/* Target vue-form-generator's radio button containers */
.vfg-field-radios .form-check {
  display: inline-block;
  margin-right: 1.5rem; /* Add spacing between options */
}

This forces the radio containers to display inline, achieving the horizontal alignment you want.

Full Modified Schema Snippet

Here’s what your updated fields array for the gender section will look like:

{
  fields: [{
    type: "input",
    inputType: "text",
    label: "Full Name",
    model: "fullName",
    placeholder: "Enter Full Name",
    required: true,
    styleClasses:'col-md-3'
  }, {
    type: "radios",
    label: "Gender",
    model: "gender",
    values: [
      "Male",
      "Female",
      "Other"
    ],
    styleClasses:'col-md-3',
    inputClasses: 'form-check-inline' // Added this line
  }]
}

Either approach will get your gender radio buttons aligned horizontally as you need.

内容的提问来源于stack exchange,提问作者Ashwini

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:35:53