2017-05-24 9 views
1

純粋なCSSとHTMLを使用して作成したアコーディオンリストのコードは次のとおりです。見出しをクリックすると、テキストが別の背景色で飛んできます。どのように私はそれを開くと閉じるためにクリックしたときに、テキストとdif背景色のコンテナがフェードインまたはフェードインするようにしますか?不透明度を0から1に設定するのと同じですか?何でも助けてくれる、歓声。フェードコンテナイン/アウトCSS

.wrapper { 
 
    max-width: 960px; 
 
    margin: 0 auto; 
 
} 
 

 

 
/* Acordeon styles */ 
 

 
.tab { 
 
    position: relative; 
 
    margin-bottom: 1px; 
 
    width: 100%; 
 
    overflow: hidden; 
 
} 
 

 
.bold { 
 
    font-weight:bold; 
 
    color: #005bab; 
 
    } 
 

 
.top { 
 
    margin-top:-20px; 
 
    text-align: center; 
 
    font-size:13px; 
 
} 
 

 
.input { 
 
    position: absolute; 
 
    opacity: 0; 
 
    z-index: -1; 
 
} 
 

 
.label { 
 
    position: relative; 
 
    text-align: center; 
 
    display: block; 
 
    padding: 0 0 0 1em; 
 
    color: #005bab; 
 
    background: #e2ecf6; 
 
    font-size: 14px; 
 
    font-family: Verdana; 
 
    font-weight: bold; 
 
    line-height: 6; 
 
    cursor: pointer; 
 
} 
 

 
.tab-content { 
 
    max-height: 0; 
 
    overflow: hidden; 
 
    padding: 0px; 
 
    -webkit-transition: max-height .5s; 
 
    -o-transition: max-height .5s; 
 
    transition: max-height .5s; 
 
    padding-left: 35px; 
 
    background: #c3d7ea; 
 
} 
 

 
.tab-content .container { 
 
    padding: 1em; 
 
    margin: 0; 
 
    transform: scale(0.6); 
 
    -webkit-transition: transform .5s; 
 
    -o-transition: transform .5s; 
 
    transition: transform .5s; 
 
    background: #f4f8fc; 
 
} 
 

 

 
/* :checked */ 
 

 
.input:checked~.tab-content { 
 
    max-height: 25em; 
 
} 
 

 
.input:checked~.tab-content .container { 
 
    transform: scale(1); 
 
} 
 

 
/* Icon */ 
 

 
.label::after { 
 
    position: absolute; 
 
    left: 0; 
 
    top: 0; 
 
    display: block; 
 
    width: 3em; 
 
    height: 3em; 
 
    line-height: 3; 
 
    text-align: center; 
 
    -webkit-transition: all .35s; 
 
    -o-transition: all .35s; 
 
    transition: all .35s; 
 
} 
 

 
.input[type=checkbox]+.label::after { 
 
    content: "+"; 
 
} 
 

 
.input[type=radio]+.label::after { 
 
    content: ""; 
 
} 
 

 
.input[type=checkbox]:checked+.label::after { 
 
    transform: rotate(315deg); 
 
} 
 

 
.input[type=radio]:checked+.label::after { 
 
    transform: rotateX(180deg); 
 
} 
 

 
.bottombar { 
 
    content: ""; 
 
    display: block; 
 
    height: 1em; 
 
    width: 100%; 
 
    background-color: #00688B; 
 
}
<div class="wrapper"> 
 
    <div class="tab"> 
 
    <input name="tabs" class="input" id="tab-one" type="checkbox" /> 
 
    <label class="label" for="tab-one">Label One</label> 
 
    <div class="tab-content"> 
 
     <div class="container"> 
 
     <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur, architecto, explicabo perferendis nostrum, maxime impedit atque odit sunt pariatur illo obcaecati soluta molestias iure facere dolorum adipisci eum? Saepe, itaque.</p> 
 
     </div> 
 
    </div> 
 
    </div> 
 
    <div class="tab"> 
 
    <input name="tabs" class="input" id="tab-two" type="checkbox" /> 
 
    <label class="label" for="tab-two">Label Two</label> 
 
    <div class="tab-content"> 
 
     <div class="container"> 
 
     <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur, architecto, explicabo perferendis nostrum, maxime impedit atque odit sunt pariatur illo obcaecati soluta molestias iure facere dolorum adipisci eum? Saepe, itaque.</p> 
 
     </div> 
 
    </div> 
 
    </div> 
 
    <div class="tab"> 
 
    <input name="tabs" class="input" id="tab-three" type="checkbox" /> 
 
    <label class="label" for="tab-three">Label Three</label> 
 
    <div class="tab-content"> 
 
     <div class="container"> 
 
     <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur, architecto, explicabo perferendis nostrum, maxime impedit atque odit sunt pariatur illo obcaecati soluta molestias iure facere dolorum adipisci eum? Saepe, itaque.</p> 
 
     </div> 
 
    </div> 
 
    </div> 
 
    <div class="bottombar"></div> 
 
</div>

+0

? https://codepen.io/anon/pen/pPYoxY –

+0

このような並べ替え:https://codepen.io/chrisbuttery/pen/cxnmJだから、見出しをクリックして開閉すると、コンテナはフェードイン/フェードアウトします。 –

答えて

1

私はあなたが正しくあなたがtransition複数のプロパティにする必要があります理解していた場合。それは非常に簡単です。単一のプロパティ遷移に使用するのと同じ構文を使用しますが、変換する各プロパティに対してカンマで区切って行います,。たとえば:

.selector { 
    color: white; 
    opacity: 0; 
    background-color: blue; 
    transition: color 500ms ease-in-out, opacity 1000ms ease-in, background-color 500ms linear; 
} 

私はopacityを設定するとともに、.tab-content .containerであなたのtransitionプロパティを更新しました。その後、.input:checked〜.tab-content .container`でopacityと定義されています。このような

.wrapper { 
 
    max-width: 960px; 
 
    margin: 0 auto; 
 
} 
 

 

 
/* Acordeon styles */ 
 

 
.tab { 
 
    position: relative; 
 
    margin-bottom: 1px; 
 
    width: 100%; 
 
    overflow: hidden; 
 
} 
 

 
.bold { 
 
    font-weight:bold; 
 
    color: #005bab; 
 
    } 
 

 
.top { 
 
    margin-top:-20px; 
 
    text-align: center; 
 
    font-size:13px; 
 
} 
 

 
.input { 
 
    position: absolute; 
 
    opacity: 0; 
 
    z-index: -1; 
 
} 
 

 
.label { 
 
    position: relative; 
 
    text-align: center; 
 
    display: block; 
 
    padding: 0 0 0 1em; 
 
    color: #005bab; 
 
    background: #e2ecf6; 
 
    font-size: 14px; 
 
    font-family: Verdana; 
 
    font-weight: bold; 
 
    line-height: 6; 
 
    cursor: pointer; 
 
} 
 

 
.tab-content { 
 
    max-height: 0; 
 
    overflow: hidden; 
 
    padding: 0px; 
 
    -webkit-transition: max-height .5s; 
 
    -o-transition: max-height .5s; 
 
    transition: max-height .5s; 
 
    padding-left: 35px; 
 
    background: #c3d7ea; 
 
} 
 

 
.tab-content .container { 
 
    padding: 1em; 
 
    margin: 0; 
 
    opacity: 0; 
 
    transform: scale(0.6); 
 
    -webkit-transition: transform .5s, opacity .75s; 
 
    -o-transition: transform .5s, opacity .75s; 
 
    transition: transform .5s, opacity .75s; 
 
    background: #f4f8fc; 
 
} 
 

 

 
/* :checked */ 
 

 
.input:checked~.tab-content { 
 
    max-height: 25em; 
 
} 
 

 
.input:checked~.tab-content .container { 
 
    transform: scale(1); 
 
    opacity: 1; 
 
} 
 

 
/* Icon */ 
 

 
.label::after { 
 
    position: absolute; 
 
    left: 0; 
 
    top: 0; 
 
    display: block; 
 
    width: 3em; 
 
    height: 3em; 
 
    line-height: 3; 
 
    text-align: center; 
 
    -webkit-transition: all .35s; 
 
    -o-transition: all .35s; 
 
    transition: all .35s; 
 
} 
 

 
.input[type=checkbox]+.label::after { 
 
    content: "+"; 
 
} 
 

 
.input[type=radio]+.label::after { 
 
    content: ""; 
 
} 
 

 
.input[type=checkbox]:checked+.label::after { 
 
    transform: rotate(315deg); 
 
} 
 

 
.input[type=radio]:checked+.label::after { 
 
    transform: rotateX(180deg); 
 
} 
 

 
.bottombar { 
 
    content: ""; 
 
    display: block; 
 
    height: 1em; 
 
    width: 100%; 
 
    background-color: #00688B; 
 
}
<div class="wrapper"> 
 
    <div class="tab"> 
 
    <input name="tabs" class="input" id="tab-one" type="checkbox" /> 
 
    <label class="label" for="tab-one">Label One</label> 
 
    <div class="tab-content"> 
 
     <div class="container"> 
 
     <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur, architecto, explicabo perferendis nostrum, maxime impedit atque odit sunt pariatur illo obcaecati soluta molestias iure facere dolorum adipisci eum? Saepe, itaque.</p> 
 
     </div> 
 
    </div> 
 
    </div> 
 
    <div class="tab"> 
 
    <input name="tabs" class="input" id="tab-two" type="checkbox" /> 
 
    <label class="label" for="tab-two">Label Two</label> 
 
    <div class="tab-content"> 
 
     <div class="container"> 
 
     <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur, architecto, explicabo perferendis nostrum, maxime impedit atque odit sunt pariatur illo obcaecati soluta molestias iure facere dolorum adipisci eum? Saepe, itaque.</p> 
 
     </div> 
 
    </div> 
 
    </div> 
 
    <div class="tab"> 
 
    <input name="tabs" class="input" id="tab-three" type="checkbox" /> 
 
    <label class="label" for="tab-three">Label Three</label> 
 
    <div class="tab-content"> 
 
     <div class="container"> 
 
     <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tenetur, architecto, explicabo perferendis nostrum, maxime impedit atque odit sunt pariatur illo obcaecati soluta molestias iure facere dolorum adipisci eum? Saepe, itaque.</p> 
 
     </div> 
 
    </div> 
 
    </div> 
 
    <div class="bottombar"></div> 
 
</div>

+1

完璧な、歓声! –