I am trying to get a check box to appear to the right of the input field "answer input one" I have tried playing with the display property but am really struggling with css layouts in general.what I am currently getting
Here is the code that is rendering the answer input:
<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>
And the inline styles are here:
const styles = {
createQuizContainer: {
width: '70%',
margin: 'auto',
paddingTop: 30,
paddingBottom: 40
},
answerField: {
width: '70%',
},
checkBox: {
display: 'inline',
}
};
and help would be greatly appreciated! As well as any advice on layouts with css in general!
Thanks.
To override the styles of a specific part of the component, use the global classes provided by Material UI, as described in the previous section "Overriding nested component styles" under the sx prop section.
Consider Material UI if you are an avid React user and don't have the time to build a custom UI from scratch. Consider Tailwind CSS if you want to build a custom UI within your markup while writing minimal custom css.
You could use flexbox:
render() {
return (
<div style={{ display: 'inline-flex' }}>
<div>
<TextField />
</div>
<div style={{ alignSelf: 'center' }}>
<Checkbox />
</div>
</div>
);
}
https://jsfiddle.net/2v1Legy2/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With