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

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

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

HTML5 (Hyper Text Markup Language、バージョン 5)は、マークアップ言語であるHTMLの第5版です。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

CSS

CSSはXMLやHTMLで表現した色・レイアウト・フォントなどの要素を指示する仕様の1つです。

Q&A

解決済

1回答

787閲覧

display:none→display:block で表示幅がおかしい

Take_it

総合スコア357

HTML5

HTML5 (Hyper Text Markup Language、バージョン 5)は、マークアップ言語であるHTMLの第5版です。

JavaScript

JavaScriptは、プログラミング言語のひとつです。ネットスケープコミュニケーションズで開発されました。 開発当初はLiveScriptと呼ばれていましたが、業務提携していたサン・マイクロシステムズが開発したJavaが脚光を浴びていたことから、JavaScriptと改名されました。 動きのあるWebページを作ることを目的に開発されたもので、主要なWebブラウザのほとんどに搭載されています。

CSS

CSSはXMLやHTMLで表現した色・レイアウト・フォントなどの要素を指示する仕様の1つです。

0グッド

0クリップ

投稿2019/02/24 01:18

編集2019/02/24 01:19

テーブルの表示幅についてですが、display:noneとしておいて、javascriptでdisplay:blockに切り替えると意図したとおりになりません。

(id="menu_〇"のテーブルも幅100%表示にしたいのです)

<!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <title>TEST</title> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> <meta name="robots" content="noindex,nofollow" > </head> <script> function menu_1(){ document.getElementById("menu_1").style.display="block"; document.getElementById("menu_2").style.display="none"; document.getElementById("menu_3").style.display="none"; document.getElementById("menu_4").style.display="none"; } function menu_2(){ document.getElementById("menu_1").style.display="none"; document.getElementById("menu_2").style.display="block"; document.getElementById("menu_3").style.display="none"; document.getElementById("menu_4").style.display="none"; } function menu_3(){ document.getElementById("menu_1").style.display="none"; document.getElementById("menu_2").style.display="none"; document.getElementById("menu_3").style.display="block"; document.getElementById("menu_4").style.display="none"; } function menu_4(){ document.getElementById("menu_1").style.display="none"; document.getElementById("menu_2").style.display="none"; document.getElementById("menu_3").style.display="none"; document.getElementById("menu_4").style.display="block"; } </script> <body style="background-color:#000000"> <h1 style="color:white">Menu</h1> <table style="width:100%;height:180px"> <caption style="background-color:white;border:1px solid blue;border-radius:15px;">:::選択して下さい:::</caption> <tbody> <tr> <td style="width:25%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="menu_1()">選択1</button> </td> <td style="width:25%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="menu_2()">選択2</button> </td> <td style="width:25%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="menu_3()">選択3</button> </td> <td style="width:25%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="menu_4()">選択4</button> </td> </tr> </tbody> </table> <table style="width:100%;height:180px;display:none" id="menu_1"> <tbody> <tr> <td style="width:20%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="location.href=''">選択1-1</button> </td> <td style="width:20%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="location.href=''">選択1-2</button> </td> <td style="width:20%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="location.href=''">選択1-3</button> </td> <td style="width:20%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="location.href=''">選択1-4</button> </td> <td style="width:20%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="location.href=''">選択1-5</button> </td> </tr> </tbody> </table> <table style="width:100%;height:180px;display:none" id="menu_2"> <tbody> <tr> <td style="width:20%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="location.href=''">選択2-1</button> </td> <td style="width:20%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="location.href=''">選択2-2</button> </td> <td style="width:20%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="location.href=''">選択2-3</button> </td> <td style="width:20%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="location.href=''">選択2-4</button> </td> <td style="width:20%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="location.href=''">選択2-5</button> </td> </tr> </tbody> </table> <table style="width:100%;height:180px;display:none" id="menu_3"> <tbody> <tr> <td style="width:20%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="location.href=''">選択3-1</button> </td> <td style="width:20%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="location.href=''">選択3-2</button> </td> <td style="width:20%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="location.href=''">選択3-3</button> </td> <td style="width:20%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="location.href=''">選択3-4</button> </td> <td style="width:20%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="location.href=''">選択3-5</button> </td> </tr> </tbody> </table> <table style="width:100%;height:180px;display:none" id="menu_4"> <tbody> <tr> <td style="width:20%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="location.href=''">選択4-1</button> </td> <td style="width:20%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="location.href=''">選択4-2</button> </td> <td style="width:20%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="location.href=''">選択4-3</button> </td> <td style="width:20%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="location.href=''">選択4-4</button> </td> <td style="width:20%;text-align:center"> <button style="width:90%;height:120px;font-size:xx-large;background-color:#a3ffd1;border:3px solid white;border-radius:15px" type="button" onClick="location.href=''">選択4-5</button> </td> </tr> </tbody> </table> </body> </html>

イメージ説明

表示非表示の切り替えをやめ、最初から全て表示状態(menu_〇のdisplay:noneをやめる)にすると、意図したとおり幅100%になるのですが・・・。
これは、「そういうもの」と諦めるものなのか、それとも何か間違っているのでしょうか?
イメージ説明

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

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

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

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

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

退会済みユーザー

退会済みユーザー

2019/02/24 01:47 編集

.style.display = 'table' にするか 'inline-table'
Take_it

2019/02/24 01:39

.style.display = 'table' で解決しました。 ありがとうございました。
退会済みユーザー

退会済みユーザー

2019/02/24 02:01

解決したならば、解決済みとしてください。
guest

回答1

0

自己解決

.style.display = 'table' で解決しました。

投稿2019/02/24 08:41

Take_it

総合スコア357

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問