gpt4 book ai didi

html - 使容器淡入淡出 css

转载 作者:行者123 更新时间:2023-11-28 15:35:54 25 4
gpt4 key购买 nike

下面是我使用纯 CSS 和 HTML 创建的 Accordion 列表的代码。单击标题时,我的文本会以不同的背景颜色飞入。当单击打开和关闭时,我将如何使带有文本和 dif 背景颜色的容器淡入淡出?比如将不透明度从 0 设置为 1?任何帮助,干杯。

.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>

最佳答案

如果我的理解正确,您将需要transition 多个属性。这很容易。使用与用于单个属性转换相同的语法,但对要转换的每个属性执行此操作,并用逗号 , 分隔。例如:

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

我更新了 .tab-content .container 中的 transition 属性以及设置 opacity。然后在.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>

关于html - 使容器淡入淡出 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44166292/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com