質問するログイン新規登録

Q&A

1回答

132閲覧

CSS ブレークポイント(768px)になるまでにレイアウトが崩れます

beta0503

総合スコア0

HTML

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

CSS

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

0グッド

0クリップ

投稿2026/04/10 12:16

0

0

実現したいこと

HTML,CSSを勉強しています。サイトを作っているのですがレスポンシブに問題があります。右に空白が出ます。768pxになるまでは自然に縮んで欲しいです。

発生している問題・分からないこと

右に空白が出て、画面いっぱいに広がりません。

エラーメッセージ

error

1エラーメッセージは出ません。

該当のソースコード

CSS

1@charset "UTF-8"; 2 3/* 横スクロール防止とボックスサイズ調整 */ 4html, body { 5 box-sizing: border-box; 6} 7 8*, *::before, *::after { 9 box-sizing: inherit; 10} 11 12/*共通部分*/ 13html { 14 font-size: 100%; 15} 16 17 18body { 19 font-family: 'Noto Sans JP', sans-serif; 20} 21 22a { 23 text-decoration: none; 24} 25 26/*ヘッダー*/ 27.header { 28 height: 130px; 29} 30 31.header-inner { 32 max-width: 1180px; 33 height: 100%; 34 margin-right: auto; 35 margin-left: auto; 36 padding: 0 20px; 37 display: flex; 38 justify-content: space-between; 39 align-items: center; 40} 41 42.header-logo-area { 43 width: 263px; 44 height: 73px; 45 display: flex; 46 align-items: center; 47 padding-top: 29px; 48 padding-bottom: 28px; 49} 50 51.header-logo { 52 display: block; 53 width: 100%; 54 height: auto; 55 56} 57 58.header-content { 59 height: 100%; 60 display: flex; 61 flex-direction: column; 62 gap: 7px; 63 align-items: flex-end; 64 justify-content: center; 65} 66 67.header-text { 68 font-size: 14px; 69 color: #444444; 70} 71 72.header-tel { 73 display: flex; 74 align-items: center; 75 gap: 5px; 76} 77 78.tel-pic { 79 font-size: 24px; 80 font-weight: bold; 81 color: #21A937; 82 text-decoration: none; 83} 84 85.tel-pic img { 86 width: 25px; 87 height: 25px; 88} 89 90/*ヒーローセクション*/ 91.hero { 92 background-image: url('../images/fv\ 1.png'); 93 background-size: cover; 94 background-position: center; 95 position: relative; 96 height: 947px; 97} 98 99.hero-content { 100 position: absolute; 101 margin-top: 133px; 102 margin-left: 211px; 103 display: flex; 104 flex-direction: row-reverse; 105} 106 107.hero-text-box { 108 width: 102px; 109 height: 565px; 110 padding: 24px 0; 111 background-color: #FFF; 112} 113 114.hero-text-box:first-child { 115 margin-left: 89px; 116} 117 118.hero-text { 119 writing-mode: vertical-rl; 120 font-size: 28px; 121 font-family: bold; 122 color: #444; 123 letter-spacing: 0.2em; 124 margin: 0 auto; 125} 126 127.text-color { 128 color: #21A937; 129} 130 131/*aboutセクション*/ 132.about{ 133 padding-top: 162px; 134 margin-bottom: 82px; 135} 136 137.about-inner{ 138 max-width: 1180px; 139 width: 100%; 140 display: flex; 141 margin-right: auto; 142 margin-left: auto; 143 padding: 0 20px; 144 gap: 42px; 145 box-sizing: border-box; 146} 147 148.about .text-area{ 149 max-width: 420px; 150 display: flex; 151 flex-direction: column; 152 gap: 37px; 153 align-items: flex-start; 154} 155 156.about-title { 157 font-size: 24px; 158 color: #444444; 159} 160 161.line { 162 position: relative; 163 font-size: 24px; 164 display: block; 165 width: fit-content; 166 margin-bottom: 35px; 167 z-index: 0; 168} 169 170.line::after { 171 content: ""; 172 position: absolute; 173 left: 0; 174 width: 100%; 175 bottom: 1px; 176 height: 10px; 177 background: #9FE3B0; 178 z-index: -1; 179} 180 181.line:nth-child(2) { 182 margin-bottom:0; 183} 184 185.about-text { 186 font-weight: 400; 187 line-height: 2.4; 188} 189 190.img-area img { 191 max-width: 690px; 192 height: auto; 193} 194 195/*コンテンツセクション*/ 196main { 197 background-color: #E9F0EE; 198} 199 200.main-content { 201 max-width: 1180px; 202 width: 100%; 203 padding: 78px 20px 113px 20px; 204 margin-right: auto; 205 margin-left: auto; 206 box-sizing: border-box; 207} 208 209.service-title { 210 text-align: center; 211 margin: 0 auto 70px auto; 212} 213 214.message { 215 text-align: center; 216 margin-bottom: 34px; 217} 218 219/*サービスカード*/ 220.service-list { 221 display: grid; 222 grid-template-columns: 1fr 1fr 1fr; 223 gap: 20px; 224 max-width: 1180px; 225 width: 100%; 226 margin: 0 auto; 227 box-sizing: border-box; 228 padding: 0 20px; 229} 230 231.service-card { 232 height: 591px; 233 background: #FFFFFF; 234 border: 2px solid #c9c9c9; 235 padding: 40px 37px 0 37px; 236 margin-bottom: 82px; 237 box-sizing: border-box; 238 min-width: 0; 239} 240 241.service-item { 242 display: flex; 243 flex-direction: column; 244 height: 100% 245} 246 247.service-item .title { 248 text-align: center; 249 font-size: 24px; 250 margin-bottom: 45px; 251} 252 253.service-item p { 254 font-size: 16px; 255 line-height: 2.4; 256} 257 258.service-item img { 259 width: 187px; 260 height: auto; 261 margin-top: auto; 262 align-self: center; 263} 264 265/*ニュースセクション*/ 266.news-title { 267 text-align: center; 268 margin: 0 auto 70px auto ; 269} 270 271.news-list { 272 display: flex; 273 flex-direction: column; 274 background-color: #FFFFFF; 275 border-radius: 30px; 276 padding: 49px 66px 46px 66px; 277} 278 279.news-item { 280 list-style: none; 281 display: flex; 282 gap: 30px; 283 padding: 19px 0; 284 border-bottom: 2px solid #e7e7e7; 285} 286 287.news-date { 288 color: #21A937; 289} 290 291.news-category { 292 font-size: 12px; 293 background: #444444; 294 width: 80px; 295 height: 25px; 296 text-align: center; 297 line-height: 25px; 298 color: #FFFFFF; 299} 300 301.news-btn { 302 display: inline-block; 303 position: relative; 304 text-align: end; 305 text-decoration: none; 306 color: #444444; 307 margin-top: 45px; 308} 309 310.news-btn::after { 311 content: ""; 312 position: absolute; 313 top: 50%; 314 right: -25px; 315 transform: translateY(-50%); 316 317 width: 0; 318 height: 0; 319 border-left: 17px solid #444; 320 border-top: 7px solid transparent; 321 border-bottom: 7px solid transparent; 322} 323 324/*フッター*/ 325.footer-inner { 326 max-width: 1180px; 327 width: 100%; 328 height: 100%; 329 display: flex; 330 gap: 34px; 331 margin-right: auto; 332 margin-left: auto; 333 padding: 196px 20px 139px 20px; 334 box-sizing: border-box; 335} 336 337.clinic-info { 338 display: flex; 339 flex-direction: column; 340} 341 342.footer-logo { 343 margin-bottom: 52px; 344 width: 263px; 345 height: auto; 346} 347 348.address { 349 display: flex; 350 gap: 16px; 351 color: #444444; 352 margin-bottom: 25px; 353} 354 355.footer-tel { 356 margin-bottom: 28px; 357} 358 359/*テーブル*/ 360.clinic-table { 361 width: 100%; 362 border-collapse: collapse; 363 font-size: 14px; 364 font-weight: 400; 365 color: #444444; 366 border-top: 2px solid #e7e7e7; 367 border-bottom: 2px solid #e7e7e7; 368 margin-bottom: 22px; 369} 370 371.clinic-table tr:first-child th, 372.clinic-table tr:first-child td { 373 padding-top: 22px; 374} 375 376.clinic-table tr:last-child th, 377.clinic-table tr:last-child td { 378 padding-bottom: 22px; 379} 380 381.clinic-table th,td{ 382 vertical-align: top; 383} 384 385.clinic-table th { 386 padding-right: 28px; 387 text-align: left; 388 white-space: nowrap; 389 font-weight: 400; 390} 391 392.schedule { 393 position: relative; 394 display: flex; 395 flex-direction: column; 396 gap: 13px; 397 padding-left: 28px; 398} 399 400.schedule-row { 401 letter-spacing: 0.2; 402} 403 404.schedule:last-child { 405 margin-bottom: 40px; 406} 407 408/*スケジュール横ボーダー*/ 409.schedule::before { 410 content: ""; 411 position: absolute; 412 left: 0; 413 top: 19px; 414 bottom: 1px; 415 width: 2px; 416 background: #e7e7e7; 417} 418 419.morning { 420 margin-right: 17px; 421} 422.day { 423 position: relative; 424 z-index: 0; 425 margin-right: 23px; 426} 427 428/*日にち下線*/ 429.day::after { 430 position: absolute; 431 content: ""; 432 width: 100%;height: 5px; 433 left: 0; 434 bottom: 1px; 435 background: #9FE3B0; 436 z-index: -1; 437} 438.day-off th{ 439 padding-right: 28px; 440 font-weight: 400; 441} 442 443.day-off td{ 444 padding-left: 28px; 445 position: relative; 446} 447 448/*休診横ボーダー*/ 449.day-off td::before { 450 content: ""; 451 position: absolute; 452 left: 0; 453 top: 0; 454 bottom: 17px; 455 width: 2px; 456 background: #e7e7e7; 457} 458 459 460 461.footer-text { 462 font-size: 11px; 463 font-weight: 400; 464 text-align: right; 465 color: #444444; 466} 467 468@media (max-width: 768px) { 469 .header-inner { 470 display: flex; 471 flex-direction: column; 472 align-items: center; 473 justify-content: center; 474 padding: 10px 0; 475 } 476 477 .header-logo-area { 478 width: 200px; 479 height: 60px; 480 } 481 482 /* ヒーローセクションのはみ出し防止 */ 483 .hero-content { 484 position: static; 485 margin: 40px auto 0 auto; 486 flex-direction: column; 487 width: 100%; 488 align-items: center; 489 padding: 0 10px; 490 box-sizing: border-box; 491 } 492 493 /* ニュースリストのはみ出し防止 */ 494 .news-list { 495 padding: 24px 10px 24px 10px; 496 } 497}

試したこと・調べたこと

  • teratailやGoogle等で検索した
  • ソースコードを自分なりに変更した
  • 知人に聞いた
  • その他
上記の詳細・結果

Gemini, chatGPTに聞いて変更しました。

補足

特になし

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

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

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

hiroki-o

2026/04/10 13:50

HTMLか画面キャプチャは提示できますか?
guest

回答1

0

 HTMLがないので想像ですが、右に空白が出るのはだいたいの場合、何かの要素の幅が大きすぎてオーバーフローを起こしていることが原因です。

 たとえば、

CSS

1.img-area img { 2 max-width: 690px; 3 height: auto; 4}

とあります。

 imgは最大で690pxの幅を消費しますから、残り幅は78pxです。この要素や親要素などのマージンパディングなどで78px以上あればオーバーフローを起こし、右に余白ができると思います。同様にpx指定している水平方向のプロパティがいくつかありますから、調べてみてはいかがでしょうか。(なんとなくですが、サービスカードが怪しいように思います)

投稿2026/04/12 00:32

編集2026/04/12 02:59
Lhankor_Mhy

総合スコア37738

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

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

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

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

ただいまの回答率
85.29%

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

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

質問する

関連した質問