inline-blockで作成したボタンが、画面幅を広げるとせり上がってきてしまいます
・inline-blockをblockにすると使用したいボタンのデザインが使えない
・floatをかけた要素にwidth: 100%などの指定をするとfloatが効かなくなる
文字を左揃えにした要素を右寄せにし、その下のボタンを通常位置に留まるようにしたい
ブロークングリッドのデザインに挑戦していて、疑似要素で背景を作りながら、極力その中に要素が収まるようコーディングをしていました。
該当のソースコード
HTML
<div class="background_pink"> <div class="float_clear"> <p class="text_right"> 当店では毎月、季節に合った草花を使って小物などを作る<br>お花の教室を行っています。色々な告知や、教室の雰囲気、<br>イベントレポートなどは随時ブログ </p> <a class="btn" href="#">MORE</a> </div> </div>
CSS
.background_pink{ position: relative; } .background_pink::after { content: ""; position: absolute; top: 10px; right: 0; background-color: pink; border-radius: 15px; width: 85%; height: 400px; z-index: -5; } /* テキストをfloatで右寄せ指定 */ .text_right{ float: right; margin-bottom: 50px; padding-left: 80px; } /* floatの回り込み解除 */ .float_clear::after { content: ""; clear: both; display: block; } /* ボタンの作成 */ .btn{ position: relative; left: 100%; transform: translateX(-180%); font-size: 1.2rem; display: inline-block; padding: 0 0 0 3rem; margin-right: 3rem; text-decoration: none; line-height: 3rem; } /* 丸の作成 */ .btn::before { content: ""; position: absolute; top: 0.2rem; left: 0; z-index: -1; width: 2.5rem; height: 2.5rem; background: blue; border-radius: 50%; transition: 0.3s ease-out; } /* 矢印の作成 */ .btn::after { position: absolute; content: ""; top: 42.5%; right: -1.5rem; width: 6px; height: 6px; border-top: 1.5px solid #000; border-right: 1.5px solid #000; transform: rotate(45deg); } /*hoverした際の形状*/ .btn:hover { color: white; } .btn:hover::before { width: 10.6rem; border-radius: 2rem; } .btn:hover::after { border-top: 1.5px solid white; border-right: 1.5px solid white; }
試したこと
floatを使わずにmarginを使用して右寄せすると、幅の指定をすることからレスポンシブの際に可変にならない。
長くなってしまいましたが、何卒よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/01/06 19:42 編集