質問をすることでしか得られない、回答やアドバイスがある。

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

新規登録して質問してみよう
ただいま回答率
85.47%
HTTP

HTTP(Hypertext Transfer Protocol)とはweb上でHTML等のコンテンツを交換するために使われるアプリケーション層の通信プロトコルです。

CSS

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

Q&A

解決済

1回答

1255閲覧

【css】要素が被って?左側のborderが消えてしまう解決法を教えてください

userHoog

総合スコア8

HTTP

HTTP(Hypertext Transfer Protocol)とはweb上でHTML等のコンテンツを交換するために使われるアプリケーション層の通信プロトコルです。

CSS

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

0グッド

0クリップ

投稿2021/02/16 09:31

編集2021/02/17 13:24

前提・実現したいこと

いつもお世話になっております。

https://rito105.com/step-flow-css/

上記URL①を参考にして、

<ul class="stepflow"> <li> <div class="stepflow-black">&nbsp;</div> <div class="stepflow_label">ここにラベル</div> <div class="stepflow_content"> <p>ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。</p> <p>ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。</p></div> </li> </ul>

https://copypet.jp/codedescription/499/

そして、上記URL②を参考にして、グラデーションで隠して「続きを読む」ボタンをつけようとしました。

html

1<div class="cp_box"> 2 <input id="cp01" type="checkbox"> 3 <label for="cp01"></label> 4 <div class="cp_container"> 5 6<ul class="stepflow"> 7<li> 8<div class="stepflow-black">&nbsp;</div> 9<div class="stepflow_label">ここにラベル</div> 10<div class="stepflow_content"> 11<p>ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。</p> 12<p>ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。ここに文章。</p></div> 13</li> 14</ul> 15 16</div> 17</div>

「続きを読む」のcssにコードを追加して修正する方法はありますでしょうか?
どうぞよろしくお願いいたします。

該当のソースコード

css

1/*ステップフローのCSS*/ 2 3ul.stepflow { 4 border: none; 5 margin: 1em 0.5em 1em -2em; 6 padding: 0; 7 list-style: none; 8} 9ul.stepflow > li:before, ol.stepflow > li:before { 10 background-color:#cccccc; 11} 12.stepflow li { 13 position: relative; 14 padding: 0 0 1.5em 1.8em; 15} 16.stepflow>li:before { 17 content: ""; 18 width: 3px; 19 background: #cccccc; 20 display: block; 21 position: absolute; 22 top: 28px; 23 bottom: 0; 24 left: 5px; 25} 26 27.stepflow-black { 28 content: ''; 29 display: inline-block; 30 position: absolute; 31 top: 5px; 32 left: 0; 33 width: 14px; 34 height: 14px; 35 border-radius: 50%; 36 border: solid 3px #232F3E; 37 background-color: #232F3E; 38} 39.stepflow_label { 40 padding: 3px 0px 8px 0px; 41 margin-bottom:8px; 42 color: #999999; 43 font-size: .8em; 44 font-weight: bold; 45} 46 47.stepflow_content { 48 font-size: .9em; 49 line-height: 1.5; 50 margin-top: .5em; 51 padding: 0 0 1.5em; 52 border-bottom: dashed 1px #cccccc; 53} 54/*ステップフローのCSSここまで*/ 55 56/*続きを読むのcss*/ 57.cp_box *, .cp_box *:before, .cp_box *:after { 58 -webkit-box-sizing: border-box; 59 box-sizing: border-box; 60} 61.cp_box { 62 position: relative; 63} 64.cp_box label { 65 position: absolute; 66 z-index: 1; 67 bottom: 0; 68 width: 100%; 69 height: 140px; /* グラデーションの高さ */ 70 cursor: pointer; 71 text-align: center; 72 /* 以下グラデーションは背景を自身のサイトに合わせて設定してください */ 73 background: linear-gradient(to bottom, rgba(250, 252, 252, 0) 0%, rgba(250, 252, 252, 0.95) 90%); 74} 75.cp_box input:checked + label { 76 background: inherit; /* 開いた時にグラデーションを消す */ 77} 78.cp_box label:after { 79 line-height: 1.5rem; 80 position: absolute; 81 z-index: 2; 82 bottom: 16px; 83 left: 50%; 84 width: 16rem; 85 font-family: FontAwesome; 86 content: '\f13a'' 続きをよむ'; 87 transform: translate(-50%, 0); 88 letter-spacing: 0.05em; 89 color: #ffffff; 90 border-radius: 20px; 91 background-color: rgba(27, 37, 56, 1); 92} 93.cp_box input { 94 display: none; 95} 96.cp_box .cp_container { 97 overflow: hidden; 98 height: 100px; /* 開く前に見えている部分の高さ */ 99 transition: all 0.5s; 100} 101.cp_box input:checked + label { 102 /* display: none ; 閉じるボタンを消す場合解放 */ 103} 104.cp_box input:checked + label:after { 105 font-family: FontAwesome; 106 content: '\f139'' 閉じる'; 107} 108.cp_box input:checked ~ .cp_container { 109 height: auto; 110 padding-bottom: 80px; /* 閉じるボタンのbottomからの位置 */ 111 transition: all 0.5s; 112} 113

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

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

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

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

先程の質問の方にも記述しましたが…

css

1body,div,p,ul,li { 2 margin: 0; 3 padding: 0; 4}

で余白リセットした状態で、ul.stepflowについている左のネガティブマージン-2emを0にすることで解決しませんか?

投稿2021/02/16 10:10

mai1210

総合スコア272

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

userHoog

2021/02/17 13:22

できました。 前回はややこしく質問してしまいすみませんでした。 助かりました。
mai1210

2021/02/18 02:35 編集

「マージンにマイナスの数値を入れる」というのは、「ブロック要素が元々ある位置から外側にズレる」ことになります。やめましょう。 ブラウザ側でデフォルトで付いてしまう余白やデザインがあるので、まずはリセットCSSについて調べてみてください。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.47%

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

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

質問する

関連した質問