• 解決済 Chanchan.

    (@eureka20080321)


    グリットレイアウトに挑戦しており、悩んでいます。

    画面をPCサイズにした場合の文字と画像が想定通りにうまく表示されません。

    PCサイズの場合だけは、画像上にグリットレイアウトで文字を配列しようとしています。

    rowを同じ位置に設定して、paddingで動かそうとしていました。

    できればその文字配列は、画像内に中央揃えで文字は左寄せ。

    ボタンも画像内に中央で文字の下に配置したいと考えています。

    @media screen and (min-width: 1024px)/*PC*/{
    .box_bubble{
    position: relative;
    display: grid;
    height: auto;
    width: 100%;
      grid-template-columns: auto;
    grid-template-rows: auto auto;
    }
    .bub_top-img{
    vertical-align: bottom;
    position: absolute;
    grid-column: 1 / 2;
    grid-row: 1 / 2;
    width: 100vw;
    margin-left: calc(-50vw + 50%);
    max-width: none;
    }
    .bub_top-p1{
    position: absolute;
    grid-column: 1 / 2;
    grid-row: 1 / 2;
    background-color: transparent;
    color: #3d87c3;
    font-weight: bold;
    font-size: 1.5em;
    height: 100px;
    padding-top: 1em;
    padding-left: 10em;
    }
    .bub_top-p2{
    position: absolute;
      grid-column: 1 / 2;
    grid-row: 1 / 2;
    background-color: transparent;
    color: #000;
       font-size: 1.2em;
    height: 100px;
    padding-top: 1em;
    padding-left: 10em;
    }
    .bub_top-p3{
    position: absolute;
    grid-column: 1 / 2;
    grid-row: 1 / 2;
    background-color: transparent;
    color:#000;
    height: 100px;
    font-size: 1.2em;
    padding-top: 1em;
    padding-left: 10em;
    }

    /*マイクロバブルトップページボタン*/
    .box_bubble a {/*aタグを画像の真ん中に*/
    position: absolute;
    grid-column: 1 / 2;
    grid-row: 2 / 3;
    top: 50%;
    left: 50%;
    -ms-transform: translate(-50%,-50%);
    -webkit-transform: translate(-50%,-50%);
    transform: translate(-50%,-50%);
    /*以下装飾*/
    margin:0;/*余計な隙間を除く*/
    font-size: 0.875em;/*文字サイズ*/
    font-weight: bold;
    border: solid #000 0.8px; /*線で囲う*/
    padding: 10px;/*文字と線の間の余白*/
    color: #000;/*文字色*/
    text-decoration: none;/*下線を表示させない*/
    border-radius: 60px;/*ボタンの角を丸く*/
    }

    .box_bubble a:hover{/*カーソルを当てたとき*/
    background: rgba(255, 255, 255, 0.3);/*背景を半透明に*/
    }

    .bub_top-p3を加えるとなぜか?画像の後ろに文字が消えてしまいます。

    そしてボタンが半分だけ表示されます。

    どうかご教授いただけると助かります。

    よろしくお願いします。

    ヘルプの必要なページ: [リンクを見るにはログイン]

9件の返信を表示中 - 1 - 9件目 (全9件中)
  • モデレーター 瀬戸内ことり (Setouchi Kotori)

    (@setouchikotori)

    お示しいただいている URL だけではどのようなレイアウトを実現されたいのかを計りかねますが・・・

    お使いのテーマ「Beautiplus」でも、WordPress 標準の「グリッド」ブロックが使えます。

    また、ボタンにネガティブマージンが設定できるので、これらを合わせると、コードを書かなくてもご希望のレイアウトは実現可能かもしれません。

    グリッドブロックの下にボタンブロックを置き、ボタンの上余白 (margin-top) をマイナスに設定してみてください。

    (ご希望のレイアウトと違っていたらすみません。イメージ画像を添付していただけると、もう少しアドバイスできることがあるかもしれません)

    モデレーター 瀬戸内ことり (Setouchi Kotori)

    (@setouchikotori)

    ちなみに、

    ボタンの上余白 (margin-top) をマイナスに設定してみてください。

    ノーコードでできます。

    トピック投稿者 Chanchan.

    (@eureka20080321)

    瀬戸内ことりさま

    年末の大変お忙しい中、ご回答いただきありがとうございます。
    返信が遅くなり申し訳ございませんでした。

    おっしゃるようにブロック等を使うと良いと思います。
    少し思う所があり、勉強を兼ねてコードを使ってみています。

    (margin-top)マイナスも後ほど実行してみます。

    お示しいただいている URL だけではどのようなレイアウトを実現されたいのかを計りかねますが・・・

    ちなみに質問時に、使ったhtmlも載せたほうが良かったという事でしょうか?
    当方、素人で理解しておらず申し訳ございません。
    引き続きアドバイスいただけますと助かります。

    よろしくお願いします。

    モデレーター 瀬戸内ことり (Setouchi Kotori)

    (@setouchikotori)

    理想形を可視化されたもの (スクショや手描き) とコードをご共有いただくと回答がつきやすいかなと思います。

    トピック投稿者 Chanchan.

    (@eureka20080321)

    ご回答いただきありがとうございます。

    その様な方法でも良いんですね。ぜひ今後の参考にさせていただきます!考えをまとめて改めて質問をさせていただこうと思います。本当にありがとうございました。

    モデレーター 瀬戸内ことり (Setouchi Kotori)

    (@setouchikotori)

    • position: absoluteを多用しているため、要素が期待通りに配置されていない可能性があります。
    • 文字が画像の後ろに隠れているのは、z-indexが設定されていないことが原因かなと思います。
    • ボタンが中央揃えで半分だけ表示される場合、transformの設定や親要素の高さが影響している可能性があります。
    @media screen and (min-width: 1024px) /*PC*/ {
    .box_bubble {
    position: relative;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto; /* 行を自動調整 */
    height: auto;
    width: 100%;
    }

    .bub_top-img {
    grid-column: 1 / -1;
    grid-row: 1 / 2;
    width: 100%;
    height: auto;
    }

    .bub_top-p1,
    .bub_top-p2,
    .bub_top-p3 {
    grid-column: 1 / -1;
    grid-row: 1 / 2;
    color: #3d87c3;
    font-size: 1.5em;
    font-weight: bold;
    text-align: left;
    z-index: 2; /* 文字を前面に表示 */
    align-self: center; /* 縦中央揃え */
    justify-self: start; /* 左揃え */
    padding: 10px;
    background-color: transparent;
    }

    .bub_top-p2 {
    color: #000;
    font-size: 1.2em;
    }

    .bub_top-p3 {
    color: #000;
    font-size: 1.2em;
    }

    /* ボタンのスタイル */
    .box_bubble a {
    grid-column: 1 / -1;
    grid-row: 2 / 3;
    justify-self: center; /* 横中央揃え */
    align-self: center; /* 縦中央揃え */
    font-size: 0.875em;
    font-weight: bold;
    border: solid #000 0.8px;
    padding: 10px 20px;
    color: #000;
    text-decoration: none;
    border-radius: 60px;
    z-index: 3; /* ボタンを前面に表示 */
    background: rgba(255, 255, 255, 0.8);
    }

    .box_bubble a:hover {
    background: rgba(255, 255, 255, 0.3);
    }
    }

    お書きになったコードとこちらを比較してみてください。

    ※ 検証していないため、ご希望どおりの表示になるかどうかはご自身でお試しいただき、適宜修正なさってくださいね。

    トピック投稿者 Chanchan.

    (@eureka20080321)

    ありがとうございます!とても助かります。

    時間をとってじっくりと、お伝えいただいたコードと比較しながらやってみます。

    モデレーター 瀬戸内ことり (Setouchi Kotori)

    (@setouchikotori)

    はいー!
    ぜひとも実践されてみてください!

    がんばってくださいねー!

    トピック投稿者 Chanchan.

    (@eureka20080321)

    瀬戸内ことりさま

    こんにちは
    解決ずみにしているのに、申し訳ございません。まだ目に留まることを祈りながらコメントをさせていただきます。
    教えていただきましたコードを元に、数日色々と奮闘してみましたが手詰まりとなってしまったので、もう少し相談に乗っていただけないでしょうか?

    ・上段は教わったコードを反映させたものです。最初のタイトル「デットクスで~」を文字センター、左右センターを維持したままもっと上位置にしたい。
    ・ボタンがまた半分の位置で止まってしまった。

    ・理想は同じものが下段に表示されていると思いますが、そのようにPC表示の時だけ写真を差し替えたいのですが、文言が画像上にならず、上段に表示されてしまう。

    /*上段部分のHTML*/
    <div class="box_bubble">
    <img class="bub_top-img" src="https://eureka.salon/wp-content/uploads/2024/11/bubble_04-scaled.jpeg" alt="画像">
    <div class="bub_top-p1">デトックスで始める予防美容<br>プロ用ナノバブルの登場です。</div>
    <div class="bub_top-p2">使うのは閉じ込めた水と空気だけ。</div>
    <div class="bub_top-p3">大切なのは「無害」であるということ。</div>
    <a href="https://eureka.salon/予防美容/" class="bub_top-btn">もっと詳しく</a>
    <video class="bub_top-video" autoplay loop muted playsinline width="100%" controlslist="nodownload nofullscreen noremoteplayback" src="https://eureka.salon/wp-content/uploads/2024/11/EUREKA_marbb-White02.mp4"></video>
    </div>
    /*下段部分のHTML*/
    <div class="box_bubble">
    <picture>
    <source media="screen and (max-width:480px)" img class="bub_top-img" srcset="https://eureka.salon/wp-content/uploads/2024/11/bubble_04-scaled.jpeg">
    <source media="screen and (min-width:480px) and (max-width:768px)" img class="bub_top-img" srcset="https://eureka.salon/wp-content/uploads/2024/11/bubble_04-scaled.jpeg">
    <source media="screen and (min-width:768px) and (max-width:1024px)" img class="bub_top-img" srcset="https://eureka.salon/wp-content/uploads/2024/11/bubble_04-scaled.jpeg">
    <source media="screen and (min-width:1024px)" img class="bub_top-img" srcset="https://eureka.salon/wp-content/uploads/2024/11/bubble_01-scaled.jpeg">
    <img class="bub_top-img" src="https://eureka.salon/wp-content/uploads/2024/11/bubble_04-scaled.jpeg" alt="画像">
    </picture>
    <div class="bub_top-p1">デトックスで始める予防美容<br>プロ用ナノバブルの登場です。</div>
    <div class="bub_top-p2">使うのは閉じ込めた水と空気だけ。</div>
    <div class="bub_top-p3">大切なのは「無害」であるということ。</div>
    <a href="https://eureka.salon/予防美容/" class="bub_top-btn">もっと詳しく</a>
    <video class="bub_top-video" autoplay loop muted playsinline width="100%" controlslist="nodownload nofullscreen noremoteplayback" src="https://eureka.salon/wp-content/uploads/2024/11/EUREKA_marbb-White02.mp4"></video>
    </div>
    /*行ったCSS*/
    @media screen and (min-width: 1024px) /*PC*/ {
    .box_bubble {
    position: relative;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto; /* 行を自動調整 */
    height: auto;
    width: 100%;
    }

    .bub_top-img {
    grid-column: 1 / -1;
    grid-row: 1 / 2;
    width: 100%;
    height: auto;
    width: 100vw;/*画像幅いっぱい*/
      margin-left: calc(-50vw + 50%);
    max-width: none;
    }

    .bub_top-p1,
    .bub_top-p2,
    .bub_top-p3 {
    grid-column: 1 / -1;
    grid-row: 1 / 2;
    color: #3d87c3;
    font-size: 3em;
    font-weight: bold;
    text-align: left;
    z-index: 2; /* 文字を前面に表示 */
    align-self: center; /* 縦中央揃え */
    justify-self: center; /* 文字を中央揃え */
    padding: 10px;
    background-color: transparent;
    padding-top: 10px;
    }

    .bub_top-p2 {
    color: #fff;
    font-size: 2em;
    padding-top: 200px;
    align-self: center;
    justify-self: center;
    }

    .bub_top-p3 {
    color: #fff;
    font-size: 2.5em;
    padding-top: 300px;
    align-self: center;
    justify-self: center;
    }

    /* ボタンのスタイル */
    .box_bubble a {
    grid-column: 1 / -1;
    grid-row: 2 / 3;
    justify-self: center; /* 横中央揃え */
    align-self: center; /* 縦中央揃え */
    font-size: 0.875em;
    font-weight: bold;
    border: solid #000 0.8px;
    padding: 10px 20px;
    color: #000;
    text-decoration: none;
    border-radius: 60px;
    z-index: 3; /* ボタンを前面に表示 */
    background: rgba(255, 255, 255, 0.8);
    }

    .box_bubble a:hover {
    background: rgba(255, 255, 255, 0.3);
    }
    .bub_top-video{
    display: none;
    }
    }

    大変読みづらいかもしれませんが、どうぞよろしくお願いします。
    下に見ていただきたいページを新たに記しました。

    https://eureka.salon/トップページpc用の表示テストページ

9件の返信を表示中 - 1 - 9件目 (全9件中)
  • このトピックに返信するにはログインが必要です。