首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >复选框触发的可折叠动画

复选框触发的可折叠动画
EN

Stack Overflow用户
提问于 2017-10-03 20:24:59
回答 1查看 38关注 0票数 0

我想知道是否有人能帮我弄个动画。我有崩溃的div,由隐藏的复选框触发。我可以动画的复选框,但div本身没有动画。我尝试过在多个类上设置转换,但没有运气,我承认,我在CSS方面并不强。有什么想法吗?提前感谢!

CSS:

代码语言:javascript
复制
body {
  font-family: "Open Sans", "Sans-serif", Arial;
  letter-spacing: 0.03em;
  padding: 5px;
  color: #435757;
}
div.main {
  width: 1000px;
  margin-left: auto;
  margin-right: auto;

}
div.content {      
  border-left: 3px solid;
  border-color: #0066cc;
  padding-left: 15px;      
  width: 95%;
  margin-left: auto;
  margin-right: auto;
}
div.labeltab {
  border-radius: 10px;
  background-color: rgba(255, 255, 255, 0.2);
  margin-top: 15px;
  margin-bottom: 15px;
}

.toggle-box {
  display: none;
}
.toggle-box + label {
  padding: 10px;
  cursor: pointer;
  display: block;
  clear: both;
  font-size: 21px;
  margin-right: auto;
  margin-bottom: 5px;
  text-align: left;
}
.toggle-box + label:hover {
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
}
.toggle-box + label + div {
  display: none;
  margin-left: 0px;
  margin-right: auto;
  -webkit-transition: all 0.5s;
  transition: all 0.5s;
}
.toggle-box:checked + label {
  color: #0066cc;
  font-style: italic;
}
.toggle-box:checked + label + div {
  display: block;
  margin-right: auto;
}
.toggle-box + label:before {
  content: "";
  display: block;
  float: left;
  font-size: 21px;
  font-weight: 300;
  border-right: 3px solid;
  border-bottom: 3px solid;
  width: 7px;
  height: 7px;
  transform: rotate(-45deg);
  margin-top: 6px;
  margin-right: 20px;
  margin-left: auto;
  text-align: left;
  -webkit-transition: all 0.5s;
  transition: all 0.5s;
}
.toggle-box:checked + label:before {
  content: "";
  color: #0066cc;
  border-right: 3px solid;
  border-bottom: 3px solid;
  width: 7px;
  height: 7px;
  transform: rotate(45deg);
  -webkit-transition: all 0.5s;
  transition: all 0.5s;
}

HTML:

代码语言:javascript
复制
<div class="LabelTab"><input class="toggle-box" id="identifier-8" name="grouped" type="checkbox"><label for="identifier-8"> Test 1</label>
<div>
<div class="content">
<h4>Content 1</h4>
<p>Stuff</p>
</div>
</div>
</div>
<div class="LabelTab"><input class="toggle-box" id="identifier-6" name="grouped" type="checkbox"><label for="identifier-6">Test 2</label>
<div>
<div class="content">
<h4>Content 2</h4>
<p>Stuff</p>
</div>
</div>
</div>
EN

回答 1

Stack Overflow用户

发布于 2017-10-04 18:55:30

多亏了迈克尔!我在我的内容范围内设置了一个min高度和最大高度,在.:复选+ label + div中,它可以工作。现在我有多个高度,动画匹配的div。谢谢!

代码语言:javascript
复制
body {
  font-family: "Open Sans", "Sans-serif", Arial;
  letter-spacing: 0.03em;
  padding: 5px;
  color: #435757;
}
div.main {
  width: 1000px;
  margin-left: auto;
  margin-right: auto;
}
div.content {
  border-left: 3px solid;
  border-color: #0066cc;
  padding-left: 15px;
  width: 95%;
  margin-left: auto;
  margin-right: auto;
}
div.labeltab {
  border-radius: 10px;
  background-color: rgba(255, 255, 255, 0.2);
  margin-top: 15px;
  margin-bottom: 15px;
}

.toggle-box {
  display: none;
}
.toggle-box + label {
  padding: 10px;
  cursor: pointer;
  display: block;
  clear: both;
  font-size: 21px;
  margin-right: auto;
  margin-bottom: 5px;
  text-align: left;
}
.toggle-box + label:hover {
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
}
.toggle-box + label + div {
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  margin-left: 0px;
  margin-right: auto;
  -webkit-transition: all 0.5s;
  transition: all 0.5s;
}
.toggle-box:checked + label {
  color: #0066cc;
  font-style: italic;
}
.toggle-box:checked + label + div {
  min-height: 100px;
  max-height: 1200px;
  opacity: 1; 
  margin-right: auto;
}
.toggle-box + label:before {
  content: "";
  display: block;
  float: left;
  font-size: 21px;
  font-weight: 300;
  border-right: 3px solid;
  border-bottom: 3px solid;
  width: 7px;
  height: 7px;
  transform: rotate(-45deg);
  margin-top: 6px;
  margin-right: 20px;
  margin-left: auto;
  text-align: left;
  -webkit-transition: all 0.5s;
  transition: all 0.5s;
}
.toggle-box:checked + label:before {
  content: "";
  color: #0066cc;
  border-right: 3px solid;
  border-bottom: 3px solid;
  width: 7px;
  height: 7px;
  transform: rotate(45deg);
  -webkit-transition: all 0.5s;
  transition: all 0.5s;
}
代码语言:javascript
复制
<div class="LabelTab"><input class="toggle-box" id="identifier-8" name="grouped" type="checkbox"><label for="identifier-8"> Test 1</label>
  <div>
    <div class="content">
      <h4>Content 1</h4>
      <p>Stuff</p>
    </div>
  </div>
</div>
<div class="LabelTab"><input class="toggle-box" id="identifier-6" name="grouped" type="checkbox"><label for="identifier-6">Test 2</label>
  <div>
    <div class="content">
      <h4>Content 2</h4>
      <p>Stuff</p>
    </div>
  </div>
</div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46552841

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档