外部CSSのスタイル設定にてメディアクエリを使用してレスポンシブ対応にしているのですが、chromeとsafariブラウザでテーブルwidthの%が反映されていないのか、スタイルが崩れます。
thとtdのみの2カラムテーブルで通常時は
table{
width:100%;
margin:0 auto;
border-collapse:collapse;
}
td, th{
border:1px solid #ccc;
padding:10px;
}
th{
width:25%;
font-weight:normal;
background:#efefef;
text-align:left;
}
メディアクエリ設定時は
/* スマフォ 縦 */
@media only screen and (max-width:480px){
table{
margin: 0 auto ;
}
table td, th{
width:100%;
display: block;
}
textarea {
resize: vertical;
}
}
上記のようにthとtd共にwidth:100%にし2カラムを1カラム風に設定し縦にthとtdが重なっていくよう設定しました。(参照にしたページ/http://www.unionnet.jp/develop/responsive-table-css/)
これがchromeとsafariブラウザで機能せず、通常時のwith:25%も600px以下になるとchromeでは機能せず、文字もはみ出ます。safariでは文字のはみ出しなどはありませんがth内の文字が改行されてしまいます。
そこで、webkit用のハックで以下のようにいれてみました。
(参照サイト/http://hack.aipo.com/archives/11050/ )
(参照サイト/http://qiita.com/rico/items/cee85cbf1b6766f3cdb7 )
/* chrome ウィンドウサイズが600px以上の時 */
@media all and (-webkit-min-device-pixel-ratio:0) {
table{
margin: 0 auto ;
width:100%;
word-wrap: break-word;
}
th{
margin: 0 auto ;
width: 25%;
}
td{
margin: 0 auto ;
}
textarea {
resize: vertical;
}
}
/* chrome ウィンドウサイズが600px以下の時 */
@media all and (-webkit-min-device-pixel-ratio:0) and (max-width:599px) {
table{
margin: 0 auto ;
width: 100%;
word-wrap: break-word;
}
td, th{
margin: 0 auto ;
display: block;
display: flex;
width:100% ;
word-wrap: break-word;
}
textarea {
resize: vertical;
}
}
上記ハックを入れる前はchromeではthとtdの枠が重なってしまっていたのですが、その重なりはなくなりました。
しかしテーブルは依然2カラムで、thが1文字分の細さでテキストが縦に並びtd内の文字もth側にめり込んだ状態です。
これを他のブラウザ(メインはfirefox)で確認した時のように、ウィンドウサイズが600px以下の時はthとtdがwidth:100%で縦に並んでいく様にしたいです。
当方使用パソコンはMAC、OSはX(10.6.8)です。普段使用のブラウザはfire foxです。
上に載せたのはテーブル部分のみの抜粋です。
CSSもhtmlもネットからコピーしながらどう動くのか試しつつ作っている状態です。
他に必要な情報がありましたら追記いたしますので、お伝えいただければ幸いです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/02/09 02:44
2016/02/09 05:18
2016/02/09 05:40
2016/02/09 05:47