Jed*_*dda 3 html css toggle hide css-transitions
所以我有一个div应该扩展以显示切换时的列表.在这里可以看到前后状态http://reversl.net/box/但是我需要添加到我的样式中才能实现这一点?我想使用css过渡来增加效果.我并不担心浏览器兼容性,因为它仅用于学习目的.有小费吗?
<div class="box"><img src="http://www.placehold.it/250x300" alt="" />
<div class="section progress">
<h4>
<a href="#">Div Before</a>
</h4>
<div class="metrics">
<div class="meter">
<span style="width: 75%"></span>
</div><!--.meter-->
</div><!--.metrics-->
</div><!--.section-progress-->
</div><!--.box-->
<div class="box"><img src="http://www.placehold.it/250x300" alt="" />
<div class="section progress">
<h4>
<a href="#">Div After</a>
</h4>
<div class="metrics">
<div class="meter">
<span style="width: 75%"></span>
</div><!--.meter-->
</div><!--.metrics-->
</div><!--.section-progress-->
<div class="sub_section">
<ul class="list">
<li>Item 1</li>
<li class="last">Item 2</li>
</ul>
</div><!--.sub_section-->
</div><!--.box-->
.boxes {
width: 100%;
padding: 1%;
}
.box {
width: 20%;
padding: 1%;
background: #fff;
-moz-box-shadow: 2px 3px 4px 0px #e9e9e9;
-webkit-box-shadow: 2px 3px 4px 0px #e9e9e9;
box-shadow: 2px 3px 3px 0px #e9e9e9;
display: inline-block;
margin-top: 1em;
}
.box img {
margin-bottom: 1%;
}
.progress a {
margin: 0;
padding: 0;
color: #999;
text-decoration: none;
}
.metrics {
margin: -1em 0 0 0;
padding: 0;
background: #c0c0c0;
}
.accordion .progress .meter {
background: #555;
width: 100%;
position: relative;
}
.meter > span {
height: 10px;
display: block;
background-color: #777;
position: relative;
overflow: hidden;
}
.sub_section {
margin-top: 1em;
border-bottom: none;
}
.list {
padding: 0;
margin: 0;
}
.list li {
background: #dcdcdc url('http://placehold.it/40x40') no-repeat;
font-size: 11px;
color: #999;
list-style: none;
padding: 1.3em 1em 1.3em 4.5em;
margin-bottom: 5px;
}
.list .last {
border-bottom: none;
}
Run Code Online (Sandbox Code Playgroud)
我担心我无法解决您的示例代码和图像,您想要点击的内容以及您想要显示的内容.但是,以下onclick
使用纯CSS 的-like事件:
<div id="wrapper">
<ul id="top">
<li><a href="#one">One</a></li>
<li><a href="#two">Two</a></li>
</ul>
<div class="box" id="one">
<p>One</p>
<span><a href="#top">Close</a></span>
</div>
<div class="box" id="two">
<p>Two</p>
<span><a href="#top">Close</a></span>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.box {
position: absolute;
top: 20%;
left: 50%;
width: 50%;
margin-left: -25%;
border: 4px solid #000;
background-color: #f90;
/* the CSS, above, is all for aesthetic purposes, what matters is the following */
opacity: 0;
-webkit-transition: all 1s linear;
-ms-transition: all 1s linear;
-moz-transition: all 1s linear;
-0-transition: all 1s linear;
transition: all 1s linear;
}
.box:target {
opacity: 1;
-webkit-transition: all 1s linear;
-ms-transition: all 1s linear;
-moz-transition: all 1s linear;
-0-transition: all 1s linear;
transition: all 1s linear;
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,似乎(在Chromium 17/Ubuntu的11.04),不可能从动画display: none;
到display: block;
同样的转变,从height: 0
以height: auto
也失败(在突然出现的,而不是一个过渡试图要么结果.所以,在演示的内容始终是"有",但简单地隐藏(使用不透明度),然后在单击相关链接后显示.
但是对于滑动切换效果:
.box {
/* aesthetic stuff excised for brevity */
opacity: 0;
height: 0;
overflow: hidden;
-webkit-transition: all 1s linear;
-ms-transition: all 1s linear;
-moz-transition: all 1s linear;
-0-transition: all 1s linear;
transition: all 1s linear;
}
.box:target {
opacity: 1;
height: 3em;
-webkit-transition: all 1s linear;
-ms-transition: all 1s linear;
-moz-transition: all 1s linear;
-0-transition: all 1s linear;
transition: all 1s linear;
}
Run Code Online (Sandbox Code Playgroud)