javascript - 如何将我的选择放在我的开关旁边?
问题描述
您好,我有使用 React.js 的代码:
import React, { Component } from 'react';
import Select from "./components/Select/Select";
import Switch from "./components/Switch/Switch";
class App extends Component {
state = {
Test : [
{value : "0", name : "1"},
]
}
render() {
return (
<>
<div className="form-inline">
<div className="col-sm-9">
<Select list={[...this.state.Test]}/>
<Switch />
</div>
</div>
</>
);
}
}
其中 Select.js :
import React from "react";
const selectoption = ({ list }) => (
<select className="custom-select">{list.map(option => (<option key={option.value} value={option.value}>{option.name}</option>))}
</select>
);
export default selectoption;
最后一个文件 Switch.js :
import React from "react";
const switchoption = () => (<div className="custom-control custom-switch">
<input type="checkbox" className="custom-control-input" id="customSwitch1" />
<label className="custom-control-label" htmlFor="customSwitch1">Slot/Map</label>
</div>);
export default switchoption;
但问题是我没有像我想要的那样在开关旁边选择。
[![我的照片][1]][1]
非常感谢 ![1]:https ://i.stack.imgur.com/CSlRi.png
解决方案
你可以在这里使用 flexbox。类似于下面显示的代码。在 React 的情况下,使用 className 而不是 class。将应该相邻的 div 包装在父类中,该父类具有行类型的 flex-direction,并且每个子类都应该具有列类型的 flex-direction。它与表格行布局非常相似。
这个链接很有帮助:https ://css-tricks.com/snippets/css/a-guide-to-flexbox/
.parent {
display: flex;
flex-direction: row
width: 100%;
}
.child {
display: flex;
flex-direction: column;
}
<div class="parent">
<div class="child">Child 1</div>
<div class="child">Child 2</div>
</div>
推荐阅读
- vue.js - 让文本框在更改时变为红色
- javascript - 将全局附加到 Vue 实例
- node.js - 在 Firebase Admin 中验证无密码电子邮件注册
- intellij-idea - 如何在 IntelliJ 中过滤 UML 图以仅显示特定类及其传递依赖项?
- apache - htaccess 404 仅适用于文件级别,但不适用于文件夹级别
- reactjs - 在 ReactJS 中自动将添加的数据反映到表中
- android - 用于 Android 崩溃的 ML-Kit
- javascript - 在 JavaScript 中,我似乎无法为布尔值是否为真/假做出 if 语句
- react-native - > 任务:react-native-wifi-reborn:compileDebugJavaWithJavac FAILED (React-Native)
- android - 切换夜间模式和媒体播放器停止后应用程序崩溃