标签和输入框设置为不在同一行
时间: 2024-02-25 09:53:09 浏览: 29
你可以使用 CSS 中的 display 属性来设置标签和输入框不在同一行。具体做法是将标签的 display 属性设置为 inline-block,将输入框的 display 属性设置为 block。这样标签和输入框就会在不同的行上显示。
例如,下面的代码将标签和输入框分别放在不同的行上:
```
<label for="input">输入框:</label>
<input type="text" id="input" style="display: block;">
```
你也可以将样式放在 CSS 文件中,以便在多个页面上重复使用:
```
label {
display: inline-block;
}
input {
display: block;
}
```
相关问题
标签和输入框要在一行
可以将 `el-form-item` 的样式设置为 `display: flex; justify-content: space-between; align-items: center;`,同时将 `label` 标签的宽度设置为固定值,如 `width: 100px;`。这样,每个表单项的标签和输入框就会在同一行,并且标签的宽度也会固定。完整代码如下:
```html
<div style="display: flex; justify-content: center; align-items: center; width: 700px; margin: 0 auto;">
<el-form :model="user" status-icon :rules="rules" ref="ruleForm" class="demo-ruleForm" style="width: 100%;">
<el-form-item label="密码" prop="username" style="display: flex; justify-content: space-between; align-items: center; width: 100%;">
<span style="width: 100px;">密码:</span>
<el-input type="password" v-model="user.pass" autocomplete="off" width="250px"></el-input>
</el-form-item>
<el-form-item label="确认密码" prop="password" style="display: flex; justify-content: space-between; align-items: center; width: 100%;">
<span style="width: 100px;">确认密码:</span>
<el-input type="password" v-model="user.checkPass" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="身份" prop="rank" style="display: flex; justify-content: space-between; align-items: center; width: 100%;">
<span style="width: 100px;">身份:</span>
<el-select v-model="user.rank" placeholder="请选择">
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
</el-option>
</el-select>
</el-form-item>
<el-form-item style="display: flex; justify-content: center; align-items: center; width: 100%;">
<el-button type="primary" @click="submitForm">提交</el-button>
<el-button @click="resetForm">重置</el-button>
</el-form-item>
</el-form>
</div>
```
在form表单下,让输入框和单选框显示在同一行,用elmentUI
你可以使用 Element UI 中的 Grid 栅格系统来实现让输入框和单选框显示在同一行。以下是一个示例代码:
```html
<template>
<el-form>
<el-row>
<el-col :span="12">
<el-form-item label="姓名">
<el-input v-model="name"></el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="性别">
<el-radio-group v-model="gender">
<el-radio :label="1">男</el-radio>
<el-radio :label="0">女</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
</el-row>
</el-form>
</template>
<script>
export default {
data() {
return {
name: '',
gender: ''
}
}
}
</script>
```
在这个示例中,我们在 form 标签下使用了一个 el-row 标签,并在其中使用了两个 el-col 标签,分别占据了 12 个栅格的宽度。然后在每个 el-col 标签中,我们使用了 el-form-item 标签,并在其中放置了 el-input 和 el-radio-group 标签,分别用来表示输入框和单选框。这样,输入框和单选框就能够在同一行显示了。