【问题标题】:Getting material-ui components to appear inline by overriding style props通过覆盖样式道具使 material-ui 组件内联显示
【发布时间】:2017-01-26 12:42:16
【问题描述】:

我试图让一个复选框出现在输入字段“answer input one”的右侧

这是呈现答案输入的代码:

     <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>

内联样式在这里:

const styles = {
  createQuizContainer: {
    width: '70%',
    margin: 'auto',
    paddingTop: 30,
    paddingBottom: 40
  },
  answerField: {
    width: '70%',
  },
  checkBox: {
    display: 'inline',
  }

};

我们将不胜感激!以及关于一般 css 布局的任何建议!

谢谢。

【问题讨论】:

    标签: css material-ui


    【解决方案1】:

    你可以使用 flexbox:

    render() {
        return (
            <div style={{ display: 'inline-flex' }}>
                <div>
                    <TextField />
                </div>
                <div style={{ alignSelf: 'center' }}>
                    <Checkbox />
                </div>
            </div>
        );
    }
    

    https://jsfiddle.net/2v1Legy2/1/

    【讨论】:

    • 不客气。如果此答案对您有用,您能否设置为“已回答”?谢谢!
    【解决方案2】:

    我将复选框的 css 更改为:

    checkbox: {
        float: 'right',
        width: '10%',
        marginTop: '7%'
      }
    

    原样是以前的全宽。不是一个很好的解决方案,但无论如何都能到达那里

    【讨论】:

      猜你喜欢
      • 2020-01-30
      • 2019-03-07
      • 2020-02-21
      • 2021-09-15
      • 2020-05-27
      • 1970-01-01
      • 2020-05-23
      • 2020-08-10
      • 2021-06-30
      相关资源
      最近更新 更多