前提
React.jsにて
map関数を使ってTableを作成しています。
実現したいこと
map関数を使って表示している
tbodyタグの箇所のバックグランドカラーをストライプ表示したい(Bootstrap使用)
該当のソースコード
React.js
1<table className="table table-striped table-bordered"> 2<thead className="table_thead "> 3 <tr className="table_font_color"> 4 <th scope="col">Device Name</th> 5 <th scope="col">Type</th> 6 <th scope="col">Room</th> 7 </tr> 8</thead> 9{entities.map((entity, i) => ( 10<tbody> 11 <tr className="table_font_color"> 12 <th scope="row"> 13 <Icon entityKey={entity.key} type={entity.type} state={entity.state} entityID={entity.entity_id} objectID={entity.object_id} /> 14 <p className="">{entity.entity_id}</p> 15 </th> 16 <td className="align-middle"> 17 {entity.key === "camera" && <div>Smart Camera</div>} 18 {entity.key === "cover" && <div>Garage</div>} 19 {entity.key === "climate" && <div>Smart Themostat</div>} 20 {entity.key === "lock" && <div>Smart Lock</div>} 21 {entity.key === "light" && <div>Smart Light</div>} 22 {entity.key === "sensor" && <div>Sensor</div>} 23 {entity.key === "switch" && <div>Smart Plug</div>} 24 </td> 25 <td className="align-middle table_rightside"> 26 {entity.key === "switch" && <button className="btn btn-primary button_table_rightside">Unassigned</button>} 27 {entity.key === "sensor" && <button className="btn btn-primary button_table_rightside">Unassigned</button>} 28 {entity.key === "light" && <div className="table_rightside_p"><p>{entity.room_name}</p><img className="ic_edit_in_table" src={ic_edit} /></div>} 29 {entity.key === "camera" && <div className="table_rightside_p"><p>{entity.room_name}</p><img className="ic_edit_in_table" src={ic_edit} /></div>} 30 {entity.key === "climate" && <div className="table_rightside_p"><p>{entity.room_name}</p><img className="ic_edit_in_table" src={ic_edit} /></div>} 31 {entity.key === "cover" && <div className="table_rightside_p"><p>{entity.room_name}</p><img className="ic_edit_in_table" src={ic_edit} /></div>} 32 {entity.key === "lock" && <div className="table_rightside_p"><p>{entity.room_name}</p><img className="ic_edit_in_table" src={ic_edit} /></div>} 33 </td> 34 </tr> 35 36</tbody> 37))}; 38</table>
CSS
1.table_thead { 2 background-color: #152D58 !important; 3} 4 5.table-bordered { 6 border: none !important; 7} 8 9.table-striped > tbody > tr:nth-child(0) > td, .table-striped > tbody > tr:nth-child(0) > th { 10 background-color: #152D58 !important; 11} 12 13.table-striped > tbody > tr:nth-child(2n+1) > td, .table-striped > tbody > tr:nth-child(2n+1) > th { 14 background-color: #1E3E75 !important; 15} 16 17.table-striped > tbody > tr:nth-child(2n) > td, .table-striped > tbody > tr:nth-child(2n) > th { 18 background-color: #152D58 !important; 19} 20 21table.table-bordered > thead > tr > th{ 22 border:3px solid #022055 !important; 23} 24 25.table-bordered td { 26 border:3px solid #022055 !important; 27} 28 29.table-bordered th { 30 border:3px solid #022055 !important; 31} 32 33.table_font_color { 34 color: white !important; 35} 36
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。