我试图让一个复选框出现在输入字段“回答输入一”的右侧我尝试过使用 display 属性,但我真的很喜欢 css 布局。我目前得到的
这是呈现答案输入的代码:
<div>
<TextField
hintText="An informative question title..."
fullWidth
floatingLabelText="Question Title"
value={questionTitle}
onChange={(e) => this.props.questionTitleChanged(e.target.value)}
/>
<TextField
floatingLabelText="Answer Input 1"
onChange={(e) => this.props.questionInputChanged({
inputIndex: 0,
value: e.target.value,
correct: false
})}
value={questionInputs[0].value}
style={styles.answerField}
/>
<Checkbox
onCheck={() => {
let correctOrIncorrect = null;
if (questionInputs[0].correct) {
correctOrIncorrect = false;
} else { correctOrIncorrect = true; }
this.props.questionInputChanged({
inputIndex: 0,
value: null,
correct: correctOrIncorrect });
}}
style={styles.checkbox}
/>
</div>
Run Code Online (Sandbox Code Playgroud)
内联样式在这里:
const styles = {
createQuizContainer: {
width: '70%',
margin: 'auto',
paddingTop: 30,
paddingBottom: 40
},
answerField: {
width: '70%',
},
checkBox: {
display: 'inline',
}
};
Run Code Online (Sandbox Code Playgroud)
和帮助将不胜感激!以及关于 css 布局的任何建议!
谢谢。
你可以使用弹性盒:
render() {
return (
<div style={{ display: 'inline-flex' }}>
<div>
<TextField />
</div>
<div style={{ alignSelf: 'center' }}>
<Checkbox />
</div>
</div>
);
}
Run Code Online (Sandbox Code Playgroud)
https://jsfiddle.net/2v1Legy2/1/