【问题标题】:Listing elements from top to bottom rather than horizontally从上到下而不是水平列出元素
【发布时间】:2021-01-15 01:26:25
【问题描述】:

在编码方面有点菜鸟,但我试图在我的页面上从上到下而不是从左到右列出选项。

 return (
         <div className="quizChallenge">
           <WebHeader/>
           <h2 id = "description"> {this.state.quizzes.description}</h2>
           <ol>
           <table id="t01">
             <tbody>
               <tr>
                 {this.state.options.map((option) => {
                   return (
                     <td key={option}>
                       <button disabled={!this.state.optionEnabled} onClick={() => this.checkAnswer(this.state.options.indexOf(option))}>
                         {option}
                       </button></td>
                   );
                 })}
               </tr>
             </tbody>
           </table>
           </ol>
           {currentQuestion < 8 &&
                <button className="ui inverted button" disabled={this.state.disabled} onClick={this.nextQuestion}>Next</button>
           }
           {currentQuestion === 7 &&
                <button className="ui inverted button" disabled={this.state.disabled} onClick={this.lastQuestion}>Finish Quiz!</button>
           }
         </div>
       );

有人可以帮助我以最好的方式做到这一点吗?

options currently shown horizontally

【问题讨论】:

标签: css reactjs options


【解决方案1】:

改变这个:

<tr>
 {this.state.options.map((option) => {
   return (
     <td key={option}>
       <button disabled={!this.state.optionEnabled} onClick={() => this.checkAnswer(this.state.options.indexOf(option))}>
         {option}
       </button></td>
   );
 })}
</tr>

{this.state.options.map((option) => {
   return (
    <tr>
     <td key={option}>
       <button disabled={!this.state.optionEnabled} onClick={() => this.checkAnswer(this.state.options.indexOf(option))}>
         {option}
       </button>
     </td>
    <tr>
   );
 })}

Woodrow Barlow 的解释:tr 代表“表格行”,td 代表“表格数据”。在一行中有多个数据单元格,它们水平显示。每行一个数据单元格,它们垂直显示。

【讨论】:

  • tr 代表“表格行”,td 代表“表格数据”。在一行中有多个数据单元格,它们水平显示。每行一个数据单元格,它们垂直显示。
  • @WoodrowBarlow 感谢您提供更好的解释,我在答案中使用了您的解释:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-18
  • 2012-11-20
  • 1970-01-01
  • 2012-12-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多