2017-06-26 18 views
2

私は以下のようにステップウィザードをコーディングしました。CSSウィザードのステップインデックスが機能しない

ul.progress[data-steps="2"] li { width: 49%; } 
 
ul.progress[data-steps="3"] li { width: 33%; } 
 
ul.progress[data-steps="4"] li { width: 24%; } 
 
ul.progress[data-steps="5"] li { width: 19%; } 
 
ul.progress[data-steps="6"] li { width: 16%; } 
 
ul.progress[data-steps="7"] li { width: 14%; } 
 
ul.progress[data-steps="8"] li { width: 12%; } 
 
ul.progress[data-steps="9"] li { width: 11%; } 
 

 
.progress { 
 
    width: 100%; 
 
    list-style: none; 
 
    list-style-image: none; 
 
    padding: 20px 0; 
 
    margin:0; 
 
    overflow:hidden; 
 
    border:2px solid #000; 
 
} 
 

 
.progress li { 
 
    float: left; 
 
    text-align: center; 
 
    position: relative; 
 
} 
 

 
.progress .name { 
 
    display: block; 
 
    vertical-align: bottom; 
 
    text-align: center; 
 
    margin-bottom: 25px; 
 
    color: black; 
 
    opacity: 0.3; 
 
} 
 

 
.progress .step { 
 
    color: black; 
 
    border: 3px solid silver; 
 
    background-color: silver; 
 
    border-radius: 50%; 
 
    line-height: 1.2; 
 
    width: 30px; 
 
    height: 30px; 
 
    display: inline-block; 
 
    z-index: 10; 
 
} 
 

 
.progress .step span { 
 
    opacity: 0.3; 
 
} 
 

 
.progress .active .name, 
 
.progress .active .step span { 
 
    
 
} 
 

 
.progress .step:before { 
 
    content: ""; 
 
    display: block; 
 
    background-color: silver; 
 
    height: 5px; 
 
    width: 50%; 
 
    position: absolute; 
 
    bottom: 15px; 
 
    left: 0; 
 
    z-index: 9; 
 
} 
 

 
.progress .step:after { 
 
    content: ""; 
 
    display: block; 
 
    background-color: silver; 
 
    height: 5px; 
 
    width: 50%; 
 
    position: absolute; 
 
    bottom: 15px; 
 
    right: 0; 
 
    z-index: 9; 
 
} 
 

 
.progress li:first-of-type .step:before { 
 
    display: none; 
 
} 
 

 
.progress li:last-of-type .step:after { 
 
    display: none; 
 
} 
 

 
.progress .done .step, 
 
.progress .done .step:before, 
 
.progress .done .step:after, 
 
.progress .active .step, 
 
.progress .active .step:before { 
 
    background-color: yellowgreen; 
 
} 
 

 
.progress .done .step, 
 
.progress .active .step { 
 
    border: 3px solid yellowgreen; 
 
}
 <div> 
 
      <ul class="progress" data-steps="4"> 
 
       <li class="done"> 
 
        <span class="name">Foo</span> 
 
        <span class="step"><span>1</span></span> 
 
       </li> 
 
       <li class="done"> 
 
        <span class="name">Bar</span> 
 
        <span class="step"><span>2</span></span> 
 
       </li> 
 
       <li class="active"> 
 
        <span class="name">Baz</span> 
 
        <span class="step"><span>3</span></span> 
 
       </li> 
 
       <li> 
 
        <span class="name">Quux</span> 
 
        <span class="step"><span>4</span></span> 
 
       </li> 
 
       
 
      </ul> 
 
     </div>

しかし、Zインデックスは動作しません。
"step:before、step:after"のうちの1つは9です。
"step:after"要素、つまり灰色の線が緑色の円の上に置かれているのはなぜですか? ?
私はz-indexをよく理解していません。
ありがとうございます。

+0

のz-indexが唯一の位置付け要素で動作し、あなたの 'の要素ではない.step' – j08691

+0

なぜない。ステップ要素のzインデックス動作しますか? –

+0

ご協力いただきありがとうございます。 –

答えて

2

で行ったように

は、背景に-2z-index値を与えます。 1.アクティブな.stepスパンにZ-インデックスを追加し、バックグラウンドで円にしました。

.progress .active .name, 
.progress .active .step span { 
    position:relative; 
    z-index:11; 
    opacity: 1; 
} 

.progress .active .step span { 
    border-radius: 50%; 
    line-height: 1.2; 
    width: 35px; 
    height: 29px; 
    display: inline-block; 
    z-index: 12; 
    margin:-2px 0 0 -2px; 
    padding-top:6px; 
    background-color: yellowgreen; 
} 
  • Iは.active。ステップに低いZインデックスを追加しました:。ステップより後。

    .progress .active。ステップ:{ z-index:8; }

  • 以下のコード全体をご覧ください。

    ul.progress[data-steps="2"] li { width: 49%; } 
     
    ul.progress[data-steps="3"] li { width: 33%; } 
     
    ul.progress[data-steps="4"] li { width: 24%; } 
     
    ul.progress[data-steps="5"] li { width: 19%; } 
     
    ul.progress[data-steps="6"] li { width: 16%; } 
     
    ul.progress[data-steps="7"] li { width: 14%; } 
     
    ul.progress[data-steps="8"] li { width: 12%; } 
     
    ul.progress[data-steps="9"] li { width: 11%; } 
     
    
     
    .progress { 
     
        width: 100%; 
     
        list-style: none; 
     
        list-style-image: none; 
     
        padding: 20px 0; 
     
        margin:0; 
     
        overflow:hidden; 
     
        border:2px solid #000; 
     
    } 
     
    
     
    .progress li { 
     
        float: left; 
     
        text-align: center; 
     
        position: relative; 
     
    } 
     
    
     
    .progress .name { 
     
        display: block; 
     
        vertical-align: bottom; 
     
        text-align: center; 
     
        margin-bottom: 25px; 
     
        color: black; 
     
        opacity: 0.3; 
     
    } 
     
    
     
    .progress .step { 
     
        color: black; 
     
        border: 3px solid silver; 
     
        background-color: silver; 
     
        border-radius: 50%; 
     
        line-height: 1.2; 
     
        width: 30px; 
     
        height: 30px; 
     
        display: inline-block; 
     
        z-index: 10; 
     
    } 
     
    
     
    .progress .step span { 
     
        opacity: 0.3; 
     
        display:inline-block; 
     
        margin-top:4px; 
     
        position:relative; 
     
        z-index:10; 
     
    } 
     
    
     
    
     
    .progress .active .step span { 
     
        border-radius: 50%; 
     
        line-height: 1.2; 
     
        width: 35px; 
     
        height: 29px; 
     
        display: inline-block; 
     
        z-index: 12; 
     
        margin:-2px 0 0 -2px; 
     
        padding-top:6px; 
     
        background-color: yellowgreen; 
     
    } 
     
    
     
    
     
    .progress .active .name, 
     
    .progress .active .step span { 
     
        position:relative; 
     
        z-index:11; 
     
        opacity: 1; 
     
    } 
     
    
     
    .progress .step:before { 
     
        content: ""; 
     
        display: block; 
     
        background-color: silver; 
     
        height: 5px; 
     
        width: 50%; 
     
        position: absolute; 
     
        bottom: 15px; 
     
        left: 0; 
     
        z-index: 9; 
     
    } 
     
    
     
    .progress .step:after { 
     
        content: ""; 
     
        display: block; 
     
        background-color: silver; 
     
        height: 5px; 
     
        width: 50%; 
     
        position: absolute; 
     
        bottom: 15px; 
     
        right: 0; 
     
        z-index: 9; 
     
    } 
     
    
     
    .progress li:first-of-type .step:before { 
     
        display: none; 
     
    } 
     
    
     
    .progress li:last-of-type .step:after { 
     
        display: none; 
     
    } 
     
    
     
    .progress .done .step, 
     
    .progress .done .step:before, 
     
    .progress .done .step:after, 
     
    .progress .active .step, 
     
    .progress .active .step:before { 
     
        background-color: yellowgreen; 
     
    } 
     
    
     
    
     
    .progress .active .step:after { 
     
        z-index:8; 
     
    } 
     
    
     
    .progress .done .step, 
     
    .progress .active .step { 
     
        border: 3px solid yellowgreen; 
     
    }
    <!DOCTYPE html> 
     
    <html> 
     
    <head> 
     
        <meta charset="utf-8"> 
     
        <meta name="viewport" content="width=device-width"> 
     
        <title>JS Bin</title> 
     
    </head> 
     
    <body> 
     
    <div> 
     
          <ul class="progress" data-steps="4"> 
     
           <li class="done"> 
     
            <span class="name">Foo</span> 
     
            <span class="step"><span>1</span></span> 
     
           </li> 
     
           <li class="done"> 
     
            <span class="name">Bar</span> 
     
            <span class="step"><span>2</span></span> 
     
           </li> 
     
           <li class="active"> 
     
            <span class="name">Baz</span> 
     
            <span class="step"><span>3</span></span> 
     
           </li> 
     
           <li> 
     
            <span class="name">Quux</span> 
     
            <span class="step"><span>4</span></span> 
     
           </li> 
     
           
     
          </ul> 
     
         </div> 
     
    </body> 
     
    </html>

    0

    beforeとafter要素のz-indexを-1に設定してください。

    +0

    私の背景Z-インデックスは0なので、Z-インデックスが-1の場合、そのラインは表示されません。 –

    1

    私は:before:after要素z-indexを与え、その後z-index.stepクラスを与えられていないで結果を達成することができています。

    私は.stepクラスにz-index値を与えることがその:before:after要素に影響と信じています。その詳細については、下記のコメントのMichael Coker's素晴らしい技術的な説明を参照してください。背景のようなページ上の他の要素がある場合、私はこの1つを試してみてくださいbody

    body { 
     
         background:rgba(0, 0, 0, 0.77); 
     
         z-index:-2; 
     
    } 
     
    
     
    ul.progress[data-steps="2"] li { width: 49%; } 
     
    ul.progress[data-steps="3"] li { width: 33%; } 
     
    ul.progress[data-steps="4"] li { width: 24%; } 
     
    ul.progress[data-steps="5"] li { width: 19%; } 
     
    ul.progress[data-steps="6"] li { width: 16%; } 
     
    ul.progress[data-steps="7"] li { width: 14%; } 
     
    ul.progress[data-steps="8"] li { width: 12%; } 
     
    ul.progress[data-steps="9"] li { width: 11%; } 
     
    
     
    .progress { 
     
        width: 100%; 
     
        list-style: none; 
     
        list-style-image: none; 
     
        padding: 20px 0; 
     
        margin:0; 
     
        overflow:hidden; 
     
        border:2px solid #000; 
     
    
     
    } 
     
    
     
    .progress li { 
     
        float: left; 
     
        text-align: center; 
     
        position: relative; 
     
    } 
     
    
     
    .progress .name { 
     
        display: block; 
     
        vertical-align: bottom; 
     
        text-align: center; 
     
        margin-bottom: 25px; 
     
        color: white; 
     
        opacity: 1; 
     
    } 
     
    
     
    .progress .step { 
     
        color: black; 
     
        border: 3px solid silver; 
     
        background-color: silver; 
     
        border-radius: 50%; 
     
        line-height: 1.2; 
     
        width: 30px; 
     
        height: 30px; 
     
        display: inline-block; 
     
        
     
    } 
     
    
     
    .progress .step span { 
     
        opacity: 1; 
     
    } 
     
    
     
    .progress .active .name, 
     
    .progress .active .step span { 
     
        
     
    } 
     
    
     
    .progress .step:before { 
     
        content: ""; 
     
        display: block; 
     
        background-color: silver; 
     
        height: 5px; 
     
        width: 50%; 
     
        position: absolute; 
     
        bottom: 15px; 
     
        left: 0; 
     
        z-index: -1; 
     
    } 
     
    
     
    .progress .step:after { 
     
        content: ""; 
     
        display: block; 
     
        background-color: silver; 
     
        height: 5px; 
     
        width: 50%; 
     
        position: absolute; 
     
        bottom: 15px; 
     
        right: 0; 
     
        z-index: -1; 
     
    } 
     
    
     
    .progress li:first-of-type .step:before { 
     
        display: none; 
     
    } 
     
    
     
    .progress li:last-of-type .step:after { 
     
        display: none; 
     
    } 
     
    
     
    .progress .done .step, 
     
    .progress .done .step:before, 
     
    .progress .done .step:after, 
     
    .progress .active .step, 
     
    .progress .active .step:before { 
     
        background-color: yellowgreen; 
     
    } 
     
    
     
    .progress .done .step, 
     
    .progress .active .step { 
     
        border: 3px solid yellowgreen; 
     
    }
    <div> 
     
        <ul class="progress" data-steps="4"> 
     
        <li class="done"> 
     
         <span class="name">Foo</span> 
     
         <span class="step"><span>1</span></span> 
     
        </li> 
     
        <li class="done"> 
     
         <span class="name">Bar</span> 
     
         <span class="step"><span>2</span></span> 
     
        </li> 
     
        <li class="active"> 
     
         <span class="name">Baz</span> 
     
         <span class="step"><span>3</span></span> 
     
        </li> 
     
        <li> 
     
         <span class="name">Quux</span> 
     
         <span class="step"><span>4</span></span> 
     
        </li> 
     
    
     
        </ul> 
     
    </div>

    +1

    * ".stepクラスにZ-インデックス値を与えることは、それが:beforeと:after要素に影響を与えると信じています" *正しいです。要素を 'z-index 'にすると新しいスタック順序が始まり、その子の' z-index'はすべて親から始まります。':after'要素は' .step'の子であるので、 'z-index'は親の相対値になります。親( '.step')に' z-index'がある場合、子は 'z-index'を低くすることはできません。あなたの修正はそれを行う方法です。 –

    +0

    "before"のz-indexが "step"よりも小さいのはなぜですか? "before"要素が "step" circleの上に置かれるのはなぜですか? –

    +1

    @AndrewLi上記の私のコメントを参照してください。要素は子要素の新しいスタック順序/コンテキストを開始します。子要素のz-indexを小さくする唯一の方法は、親からz-indexを削除することです。https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context –

    関連する問題