お示しいただいている URL だけではどのようなレイアウトを実現されたいのかを計りかねますが・・・
お使いのテーマ「Beautiplus」でも、WordPress 標準の「グリッド」ブロックが使えます。
また、ボタンにネガティブマージンが設定できるので、これらを合わせると、コードを書かなくてもご希望のレイアウトは実現可能かもしれません。
グリッドブロックの下にボタンブロックを置き、ボタンの上余白 (margin-top) をマイナスに設定してみてください。
(ご希望のレイアウトと違っていたらすみません。イメージ画像を添付していただけると、もう少しアドバイスできることがあるかもしれません)
瀬戸内ことりさま
年末の大変お忙しい中、ご回答いただきありがとうございます。
返信が遅くなり申し訳ございませんでした。
おっしゃるようにブロック等を使うと良いと思います。
少し思う所があり、勉強を兼ねてコードを使ってみています。
(margin-top)マイナスも後ほど実行してみます。
お示しいただいている URL だけではどのようなレイアウトを実現されたいのかを計りかねますが・・・
ちなみに質問時に、使ったhtmlも載せたほうが良かったという事でしょうか?
当方、素人で理解しておらず申し訳ございません。
引き続きアドバイスいただけますと助かります。
よろしくお願いします。
理想形を可視化されたもの (スクショや手描き) とコードをご共有いただくと回答がつきやすいかなと思います。
ご回答いただきありがとうございます。
その様な方法でも良いんですね。ぜひ今後の参考にさせていただきます!考えをまとめて改めて質問をさせていただこうと思います。本当にありがとうございました。
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);
}
}
お書きになったコードとこちらを比較してみてください。
※ 検証していないため、ご希望どおりの表示になるかどうかはご自身でお試しいただき、適宜修正なさってくださいね。
ありがとうございます!とても助かります。
時間をとってじっくりと、お伝えいただいたコードと比較しながらやってみます。
瀬戸内ことりさま
こんにちは
解決ずみにしているのに、申し訳ございません。まだ目に留まることを祈りながらコメントをさせていただきます。
教えていただきましたコードを元に、数日色々と奮闘してみましたが手詰まりとなってしまったので、もう少し相談に乗っていただけないでしょうか?
・上段は教わったコードを反映させたものです。最初のタイトル「デットクスで~」を文字センター、左右センターを維持したままもっと上位置にしたい。
・ボタンがまた半分の位置で止まってしまった。
・理想は同じものが下段に表示されていると思いますが、そのように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用の表示テストページ