質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
CSS3

CSS(Cascading Style Sheet)の第3版です。CSS3と略されることが多いです。色やデザインを柔軟に変更することが可能になります。

Bootstrap

BootstrapはウェブサイトデザインやUIのWebアプリケーションを素早く 作成する可能なCSSフレームワークです。 Twitter風のデザインを作成することができます。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

Q&A

解決済

1回答

330閲覧

map関数を使って表示しているテーブルの tbodyタグの箇所のバックグランドカラーをストライプ表示したい(Bootstrap使用)

Tomato_leaf

総合スコア173

CSS3

CSS(Cascading Style Sheet)の第3版です。CSS3と略されることが多いです。色やデザインを柔軟に変更することが可能になります。

Bootstrap

BootstrapはウェブサイトデザインやUIのWebアプリケーションを素早く 作成する可能なCSSフレームワークです。 Twitter風のデザインを作成することができます。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

0グッド

0クリップ

投稿2022/10/18 06:02

前提

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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

React.js

1<tr className={`table_font_color ${i % 2 === 0 ? 'table-striped' : ''}`}>

そして

CSS

1.table-striped > td { 2 background-color: #1E3E75 !important; 3} 4 5.table-striped > th { 6 background-color: #1E3E75 !important; 7}

で解決しました。

投稿2022/10/18 10:30

Tomato_leaf

総合スコア173

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問