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

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

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

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

CSS

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

Q&A

1回答

1011閲覧

レスポンシブ対応が効かない!

MitsukiN

総合スコア2

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

CSS

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

0グッド

0クリップ

投稿2021/01/28 15:08

編集2021/01/28 15:17

前提・実現したいこと

PCファーストで、レスポンシブ対応させたいです。
レスポンシブ対応を実装している途中で、viewportも書いて、メディアクエリを書く順番も正しいと思うのですが、うまく表示できません。
PCファーストで書いていて、@media screen and (max-width: 959px) のcssは反映されるのですが、@media screen and (max-width: 480px) のcssは反映されません。

発生している問題・エラーメッセージ

PCファーストで書いていて、@media screen and (max-width: 959px) のcssは反映されるのですが、@media screen and (max-width: 480px) のcssは反映されません。

該当のソースコード

css

1@charset "UTF-8"; 2/* reset */ 3body, h1, h2, h3, h4, h5, h6, p, address, 4ul, ol, li, dl, dt, dd, img, form, table, tr, th, td { 5 margin: 0; 6 padding: 0; 7 border: none; 8 font-style: normal; 9 font-weight: normal; 10 font-size: 100%; 11 text-align: left; 12 border-collapse: collapse; 13} 14 15 16textarea { font-size: 100%; vertical-align:middle;} 17img { border-style: none; display: block; } 18hr { display: none; } 19em{font-style: normal} 20input{line-height:auto;vertical-align:middle;} 21strong.more{color:#c30} 22a{text-decoration: none;} 23 24html { 25 26} 27 28body { 29 font-family:'ヒラギノ角ゴ Pro W3','Hiragino Kaku Gothic Pro','メイリオ',Meiryo,'MS Pゴシック',sans-serif; 30} 31 32* { 33 -webkit-box-sizing: border-box; 34 -moz-box-sizing: border-box; 35 -o-box-sizing: border-box; 36 -ms-box-sizing: border-box; 37 box-sizing: border-box; 38} 39 40/* 上の部分は気にせずここから書く */ 41 42 #top p { 43 width: 980px; 44 margin: auto; 45 } 46 47 .logo { 48 width: 980px; 49 margin: auto; 50 } 51 52 .logo img { 53 width: 260px; 54 } 55 56 #header { 57 margin-top: 20px; 58 } 59 60 #header ul{ 61 width: 100%; 62 display: flex; 63 justify-content: center; 64 background-color: #001754; 65 color: #fff; 66 font-size: 15px; 67 list-style-type: none; 68 } 69 70 #header ul li { 71 width: 245px; 72 text-align: center; 73 border-left: 1px solid #fff; 74 } 75 76 #header li + li { 77 border-left: 1px solid #fff; 78 } 79 80 #header li:last-child { 81 border-right: 1px solid #fff; 82 } 83 84 .main_side { 85 display: flex; 86 justify-content: center; 87 } 88 89 .main { 90 width: 700px; 91 92 } 93 94 .title { 95 margin: 20px 0 10px 0; 96 font-size: 20px; 97 color: #fff; 98 background-color: #001754; 99 } 100 101 .service { 102 width: 700px; 103 display: flex; 104 justify-content: space-between; 105 } 106 107 .image_1 { 108 width: 203px; 109 } 110 111 .image_1 img { 112 width: 203px; 113 } 114 115 .image_1 h1 { 116 font-size: 18px; 117 margin:10px; 118 text-align: center; 119 } 120 121 .image_1 p { 122 font-size: 15px; 123 margin-bottom: 30px; 124 } 125 126 .contents ul { 127 list-style-type: disc; 128 margin-left: 24px; 129 margin-bottom: 30px; 130 } 131 132 .sub { 133 margin-bottom: 40px; 134 } 135 136 .sub h1 { 137 color: #001754; 138 font-size: 18px; 139 border-bottom: solid 2px #000; 140 } 141 142 .sub h2 { 143 margin: 20px 0 30px 0; 144 } 145 146 .sub h2 span { 147 font-weight: bold; 148 } 149 150 .sub ul { 151 list-style-type: none; 152 display: flex; 153 margin-left: 0; 154 } 155 156 .phone { 157 display: none; 158 } 159 160 .contents ol { 161 list-style-type: decimal; 162 margin-left: 24px; 163 margin-bottom: 60px; 164 } 165 166 .side { 167 float: right; 168 margin-top: 10px; 169 } 170 171 .side img { 172 width: 260px; 173 height: 100px; 174 margin: 10px; 175 } 176 177 #footer { 178 background-color: #001754; 179 font-size: 13px; 180 color: #fff; 181 margin-top: 10px; 182 } 183 184 #footer p { 185 text-align: center; 186 padding: 5px; 187 } 188 189 .under_line { 190 position: absolute; 191 top: 1090px; 192 border-top: solid 2px #000; 193 z-index: 1; 194 width: 100%; 195 } 196 197 .form-title { 198 display: none; 199 } 200 201 .form-label { 202 display: none; 203 } 204 205 .phone-only { 206 display: none; 207 } 208 209 .submit { 210 display: none; 211 } 212 213 214@media screen and (max-width: 959px) { 215 216 #top p { 217 width: 60%; 218 font-size: 12px; 219 } 220 221 .logo img { 222 width: 30%; 223 } 224 225 #header { 226 margin-top: 20px; 227 } 228 229 #header ul{ 230 width: 100%; 231 display: flex; 232 justify-content: center; 233 background-color: #001754; 234 color: #fff; 235 font-size: 15px; 236 list-style-type: none; 237 } 238 239 #header ul li { 240 width: 25%; 241 text-align: center; 242 border-left: 1px solid #fff; 243 } 244 245 #header li + li { 246 border-left: 1px solid #fff; 247 } 248 249 #header li:last-child { 250 border-right: 1px solid #fff; 251 } 252 253 .main_side { 254 display: flex; 255 justify-content: center; 256 } 257 258 .main { 259 width: 75%; 260 261 } 262 263 .title { 264 margin: 20px 5% 10px 5%; 265 font-size: 18px; 266 color: #fff; 267 background-color: #001754; 268 } 269 270 .service { 271 width: 90%; 272 margin: 0 5%; 273 display: flex; 274 justify-content: space-between; 275 } 276 277 .image_1 { 278 width: 30%; 279 } 280 281 .image_1 img { 282 width: 100%; 283 } 284 285 .image_1 h1 { 286 font-size: 14px; 287 margin:10px; 288 text-align: center; 289 } 290 291 .image_1 p { 292 font-size: 13px; 293 margin-bottom: 30px; 294 } 295 296 .contents ul { 297 list-style-type: disc; 298 margin-left: 8%; 299 margin-bottom: 30px; 300 font-size: 13px; 301 } 302 303 .sub { 304 margin: 0 5% 40px 5%; 305 } 306 307 .sub h1 { 308 color: #001754; 309 font-size: 15px; 310 border-bottom: solid 2px #000; 311 } 312 313 .sub h2 { 314 margin: 20px 0 30px 0; 315 font-size: 13px; 316 } 317 318 .sub p { 319 font-size: 13px; 320 } 321 322 .sub h2 span { 323 font-weight: bold; 324 font-size: 13px; 325 } 326 327 .sub ul { 328 list-style-type: none; 329 display: flex; 330 flex-wrap: wrap; 331 margin: 0; 332 font-size: 13px; 333 } 334 335 .phone { 336 display: none; 337 } 338 339 .contents ol { 340 list-style-type: decimal; 341 margin-left: 8%; 342 margin-bottom: 60px; 343 font-size: 13px; 344 } 345 346 .side { 347 float: right; 348 margin-top: 20px; 349 margin-right: 3%; 350 } 351 352 .side img { 353 width: 100%; 354 height: 100px; 355 margin-bottom: 3%; 356 } 357 358 #footer { 359 background-color: #001754; 360 font-size: 13px; 361 color: #fff; 362 margin-top: 10px; 363 } 364 365 #footer p { 366 text-align: center; 367 padding: 5px; 368 } 369 370 #footer_logo { 371 border-top: solid 1px #000; 372 padding-top: 1%; 373 } 374 375 .under_line { 376 position: absolute; 377 top: 1090px; 378 border-top: solid 2px #000; 379 z-index: 1; 380 width: 100%; 381 } 382 383 .form-title { 384 display: none; 385 } 386 387 .form-label { 388 display: none; 389 } 390 391 .phone-only { 392 display: none; 393 } 394 395 .submit { 396 display: none; 397 } 398} 399 400@media screen and (max-width: 480px) { 401 402 #top p { 403 width: 100%; 404 font-weight: bold; 405 font-size: 10px; 406 transform: scale(0.7); 407 transform-origin: left center; 408 } 409 410 .logo img { 411 width: 50%; 412 height: 34px; 413 } 414 415 #header ul{ 416 width: 100%; 417 height: 25px; 418 display: flex; 419 justify-content: center; 420 align-items: center; 421 background-color: #001754; 422 color: #fff; 423 font-size: 11px; 424 list-style-type: none; 425 margin-top: 10px; 426 } 427 428 #header ul li { 429 width: 245px; 430 text-align: center; 431 border-left: 1px solid #fff; 432 } 433 434 #header li:last-child { 435 border-right: 1px solid #fff; 436 } 437 438 .title { 439 margin: 20px 5% 10px 5%; 440 font-size: 11px; 441 font-weight: bold; 442 color: #fff; 443 background-color: #001754; 444 height: 25px; 445 display: flex; 446 justify-content: flex-start; 447 align-items: center; 448 } 449 450 .image_1 { 451 margin: 5%; 452 } 453 454 .image_1 img { 455 width: 100%; 456 } 457 458 .image_1 h1 { 459 font-size: 15px; 460 font-weight: bold; 461 margin: 3%; 462 text-align: center; 463 } 464 465 .image_1 p { 466 font-size: 14px; 467 } 468 469 .contents ul { 470 list-style-type: disc; 471 margin-left: 8%; 472 margin-bottom: 5%; 473 font-size: 11px; 474 } 475 476 .sub { 477 margin: 5%; 478 font-size: 11px; 479 } 480 481 .sub h1 { 482 color: #001754; 483 font-weight: bold; 484 border-bottom: solid 1px #000; 485 } 486 487 .sub h2 { 488 margin: 10px 0 15px 0; 489 } 490 491 .sub h2 span { 492 font-weight: bold; 493 } 494 495 .sub ul{ 496 display: flex; 497 flex-wrap: wrap; 498 list-style-type: none; 499 margin-left: 0; 500 } 501 502 .contents ol { 503 font-size: 13px; 504 list-style-type: decimal; 505 margin-left: 8%; 506 margin-bottom: 7%; 507 } 508 509 .form-title { 510 font-size: 11px; 511 font-weight: bold; 512 color: #fff; 513 background-color: #001754; 514 margin-bottom: 5px; 515 height: 25px; 516 display: flex; 517 justify-content: flex-start; 518 align-items: center; 519 } 520 521 .phone-only { 522 margin: 5px 15px 10px 15px; 523 border: solid 1px silver; 524 } 525 526 .label { 527 background-color: silver; 528 font-size: 11px; 529 font-weight: bold; 530 height: 30px; 531 display: flex; 532 justify-content: flex-start; 533 align-items: center; 534 } 535 536 .form { 537 font-size: 11px; 538 height: 30px; 539 display: flex; 540 justify-content: flex-start; 541 align-items: center; 542 } 543 544 label { 545 margin-left: 2%; 546 } 547 548 #name { 549 width: 40%; 550 height: 20px; 551 margin: 3%; 552 padding: 0; 553 } 554 555 #age { 556 width: 15%; 557 height: 20px; 558 margin: 3%; 559 } 560 561 .sex { 562 width: 11px; 563 height: 11px; 564 } 565 566 .cb { 567 width: 11px; 568 height: 11px; 569 } 570 571 #content { 572 width: 95%; 573 height: 130px; 574 margin: 2.5%; 575 } 576 577 .submit { 578 margin: 5%; 579 display: flex; 580 justify-content: center; 581 582 } 583 584 #submit-btn { 585 font-size: 11px; 586 margin: 10px 3% 20px 3%; 587 } 588 589 .side img { 590 width: 90%; 591 height: 10%; 592 margin: 5px 5%; 593 } 594 595 .side { 596 margin-bottom: 50px; 597 } 598 599 #footer { 600 background-color: #001754; 601 color: #fff; 602 margin-top: 5px; 603 } 604 605 #footer p { 606 padding: 5px; 607 height: 10px; 608 font-size: 10px; 609 transform: scale(0.5); 610 transform-origin: center; 611 display: flex; 612 justify-content: center; 613 align-items: center; 614 } 615 616 #footer_logo { 617 display: flex; 618 justify-content: center; 619 padding-top: 3%; 620 border-top: solid 1px #000; 621 } 622 623 #footer_logo img { 624 width: 50%; 625 } 626 627} 628

html

1<!DOCTYPE html> 2<html> 3<head> 4 <meta charset="UTF-8"> 5 <title>ガーディアン</title> 6 <link rel="stylesheet" type="text/css" href="base.css"/> 7 <meta name="viewport" content="width=device-width,initial-scale=1.0" /> 8</head> 9<body> 10 <div id="top"> 11 <p>WEB戦略、CMS構築、ホームページ制作・効果アップなら東京のガーディアン</p> 12 </div> 13 14 <div class="logo"> 15 <img src="images/logo.jpg" alt="ロゴ"> 16 </div> 17 18 <div id="header"> 19 <ul> 20 <li>ナビ1</li> 21 <li>ナビ2</li> 22 <li>ナビ3</li> 23 <li>ナビ4</li> 24 </ul> 25 </div>

試したこと

viewportも書いて、メディアクエリを書く順番も正しいと思うのですが、うまく表示できません。
プログラミング初心者ですがどうしても実現したいので、ご教示お願いします。

*HTMLは文字数制限のため最初の部分だけ記載しています。

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

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

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

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

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

guest

回答1

0

確認用のブラウザーにChromeやEdgeをお使いなのでは? それだと、ウィンドウの横幅自体を480px以下にできないので、ウィンドウの幅を縮めても検証できません。

簡単に確認するには、デベロッパーツールを表示させて、ページの内容との境界線をドラッグすれば、ウィンドウサイズを変えずにページの横幅を短くできます。実際、提示されたHTMLとCSSのページで、この方法で@media screen and (max-width: 480px)の部分が反映されることを確認済みです。

補足: line-heightプロパティの値にautoは指定できません。normalの間違いかな。

投稿2021/01/28 15:34

編集2021/01/28 15:36
Daregada

総合スコア11990

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問