@kurukuppp

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

Codejumpさんの問題が難しいです。

解決したいこと

https://code-jump.com/demo/html/store1/
上記のようなサイトを練習として作っているのですが、cssがわかりません。

現在はこのように、画像とテキストが左右に離れてしまっています。
Screenshot 2025-03-05 at 13.50.13.png

画像とテキストをどうしたらセンターに寄せられるか、sec-titleとpをずらしたくない。

お願いします。

今はこんな感じで書いています。

HTML

        <section class="catalog-antique">
            <div class="flex-item">
                <div class="item">
                    <img src="img/catalog.jpg" alt="catalog">
                </div>
                <div class="item">
                    <h2 class="sec-title">Catalog</h2>
                    <p>
                        テキストテキストテキストテキストテキストテキストテキストテキストテキスト
                        テキストテキストテキストテキストテキストテキストテキストテキストテキスト
                        テキストテキストテキストテキストテキストテキストテキストテキストテキスト
                    </p>
                    <p>
                        テキストテキストテキストテキストテキストテキストテキストテキストテキスト
                        テキストテキストテキストテキストテキストテキストテキストテキストテキスト
                        テキストテキストテキストテキストテキストテキストテキストテキストテキスト
                    </p>
                    <p>
                        テキストテキストテキストテキストテキストテキストテキストテキストテキスト
                        テキストテキストテキストテキストテキストテキストテキストテキストテキスト
                        テキストテキストテキストテキストテキストテキストテキストテキストテキスト
                    </p>
                </div>
            </div>
        </section>

        <section class="catalog-antique">
            <div class="flex-item">
                <div class="item">
                    <h2 class="sec-title">Antique</h2>
                    <p>
                        テキストテキストテキストテキストテキストテキストテキストテキストテキスト
                        テキストテキストテキストテキストテキストテキストテキストテキストテキスト
                        テキストテキストテキストテキストテキストテキストテキストテキストテキスト
                    </p>
                    <p>
                        テキストテキストテキストテキストテキストテキストテキストテキストテキスト
                        テキストテキストテキストテキストテキストテキストテキストテキストテキスト
                        テキストテキストテキストテキストテキストテキストテキストテキストテキスト
                    </p>
                    <p>
                        テキストテキストテキストテキストテキストテキストテキストテキストテキスト
                        テキストテキストテキストテキストテキストテキストテキストテキストテキスト
                        テキストテキストテキストテキストテキストテキストテキストテキストテキスト
                    </p>
                    <a class="btn" href="#">Read more</a>
                </div>
                <div class="item">
                    <img src="img/antique.jpg" alt="antique">
                </div>
            </div>
        </section>

CSS

.catalog-antique {
  background-color: #f5f5f5;
  padding: 60px 0;
}
.catalog-antique .sec-title {
  margin-bottom: 40px;
}
.catalog-antique .flex-item {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}
.catalog-antique .item {
  width: 48%;
  text-align: center;
}
.catalog-antique .item img {
  max-block-size: 500px;
}
.catalog-antique .item p {
  margin-bottom: 30px;
  text-align: left;

  max-width: 501px;
}
.catalog-antique .item p:last-child {
  margin-bottom: 0;
}
0 likes

1Answer

HTML+CSSで書かれた答えが https://code-jump.com/demo/html/store1/ にあるのですから、カンニングというか、そのコードを読めばいいのではないですか?

答えの方に書いてあって、この質問の方に書いてないものはいくつかあるようですが、おそらく、以下のあたりが関わっているのではないでしょうか。

/*
中身のコンテンツの最大幅を設定し、共通で使用
*/
.wrapper {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 5%;
}
0Like

Comments

  1. @kurukuppp

    Questioner

    CSSは回答を見ずにGeminiと協力してコードを書いているのでCodejump作のお手本コードとはごっちゃになっております。ここら辺の要素に問題はないということですか?

    .catalog-antique {
    
  2. .catalog-antique にスタイルをつけることによって中央に寄せることもできますから、そのあたりは問題があるともないとも言えない感じです。
    Geminiがどのようにしてこのレイアウトを実現しようとしているのかによるのではないでしょうか?

  3. あー、でも、.catalog-antique には背景色がついていますから、幅を縮めるのは望ましくないでしょうね。触らない方がよさそうです。

  4. @kurukuppp

    Questioner

    背景色も、お手本の場合はCatalogブロックとAntiqueブロック隙間なくありますが、自分のコードの場合はこの二つの背景色に隙間が生じているんです。。
    もう一度一からCodejumpのお手本を見ながらやってみます!

    ありがとうございました :)

Your answer might help someone💌