gpt4 book ai didi

css - 通过单击加号或标签打开 CSS Accordion

转载 作者:行者123 更新时间:2023-12-02 09:21:12 25 4
gpt4 key购买 nike

我发现了一个很棒的 CSS/html codepen,它允许我在单击 label 内的文本时以 Accordion 方式查看文本。类的元素 question ,但我只遇到一个问题:

问题:

我无法使用 plus 类的加号还可以切换 Accordion 。相反,在当前的实现中,如果我单击 label 内的文本, Accordion 只会打开并允许我查看答案。类的元素 question .

就目前情况而言,如果我单击加号(属于 .plus 类),则什么也不会发生。有人可以帮我修改此代码,以便单击类 plus 的加号吗? label 内的问题文本本身元素切换答案的可见性?

这是代码笔: https://codepen.io/ihatecoding/pen/ryOpQd

这是片段:

@import url(http://fonts.googleapis.com/css?family=Open+Sans:300,800);

body {
font-family: 'Open Sans';
font-size: 1.5em;
background: #eee;
}

.content {
width: 80%;
padding: 20px;
margin: 0 auto;
padding: 0 60px 0 0;
}

.centerplease {
margin: 0 auto;
max-width: 270px;
font-size: 40px;
}

.question {
position: relative;
background: #8FBC8F;
margin: 0;
padding: 10px 10px 10px 50px;
display: block;
width:100%;
cursor: pointer;
}

.answers {
background: #999;
padding: 0px 15px;
margin: 5px 0;
height: 0;
overflow: hidden;
z-index: -1;
position: relative;
opacity: 0;
-webkit-transition: .7s ease;
-moz-transition: .7s ease;
-o-transition: .7s ease;
transition: .7s ease;
}

.questions:checked ~ .answers{
height: auto;
opacity: 1;
padding: 15px;
}

.plus {
position: absolute;
margin-left: 10px;
z-index: 5;
font-size: 2em;
line-height: 100%;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
-webkit-transition: .3s ease;
-moz-transition: .3s ease;
-o-transition: .3s ease;
transition: .3s ease;
}

.questions:checked ~ .plus {
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}

.questions {
display: none;
}
<div class='centerplease'>
FAQ accordion
</div>
<br>

<div class="content">
<div>
<input type="checkbox" id="question1" name="q" class="questions">
<div class="plus">+</div>
<label for="question1" class="question">
This is the question that will be asked?
</label>
<div class="answers">
What if the answer is really long and wraps the whole page and you never want to finish it but you have to because its the answer!
</div>
</div>

<div>
<input type="checkbox" id="question2" name="q" class="questions">
<div class="plus">+</div>
<label for="question2" class="question">
Short?
</label>
<div class="answers">
short!
</div>
</div>

<div>
<input type="checkbox" id="question3" name="q" class="questions">
<div class="plus">+</div>
<label for="question3" class="question">
But what if the question is really long and wraps the whole page and you feel like you will never finish reading the question?
</label>
<div class="answers">
This is the answer!
</div>
</div>
</div>

最佳答案

解决此问题的一个简单方法是为您的 .plus 类提供 pointer-events: none;。这允许鼠标单击加号图标,点击其后面的标签。

@import url(http://fonts.googleapis.com/css?family=Open+Sans:300,800);

body {
font-family: 'Open Sans';
font-size: 1.5em;
background: #eee;
}

.content {
width: 80%;
padding: 20px;
margin: 0 auto;
padding: 0 60px 0 0;
}

.centerplease {
margin: 0 auto;
max-width: 270px;
font-size: 40px;
}

.question {
position: relative;
background: #8FBC8F;
margin: 0;
padding: 10px 10px 10px 50px;
display: block;
width:100%;
cursor: pointer;
}

.answers {
background: #999;
padding: 0px 15px;
margin: 5px 0;
height: 0;
overflow: hidden;
z-index: -1;
position: relative;
opacity: 0;
-webkit-transition: .7s ease;
-moz-transition: .7s ease;
-o-transition: .7s ease;
transition: .7s ease;
}

.questions:checked ~ .answers{
height: auto;
opacity: 1;
padding: 15px;
}

.plus {
position: absolute;
margin-left: 10px;
z-index: 5;
font-size: 2em;
line-height: 100%;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
-webkit-transition: .3s ease;
-moz-transition: .3s ease;
-o-transition: .3s ease;
transition: .3s ease;
pointer-events: none;
}

.questions:checked ~ .plus {
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
transform: rotate(45deg);
}

.questions {
display: none;
}
<div class='centerplease'>
FAQ accordion
</div>
<br>

<div class="content">
<div>
<input type="checkbox" id="question1" name="q" class="questions">
<div class="plus">+</div>
<label for="question1" class="question">
This is the question that will be asked?
</label>
<div class="answers">
What if the answer is really long and wraps the whole page and you never want to finish it but you have to because its the answer!
</div>
</div>

<div>
<input type="checkbox" id="question2" name="q" class="questions">
<div class="plus">+</div>
<label for="question2" class="question">
Short?
</label>
<div class="answers">
short!
</div>
</div>

<div>
<input type="checkbox" id="question3" name="q" class="questions">
<div class="plus">+</div>
<label for="question3" class="question">
But what if the question is really long and wraps the whole page and you feel like you will never finish reading the question?
</label>
<div class="answers">
This is the answer!
</div>
</div>
</div>

关于css - 通过单击加号或标签打开 CSS Accordion ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42515695/

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