CSS3 过渡 : is there an on click option without using JQuery?

标签 css click hover transitions

效果很好:

<style type="text/css"> 
    div
    {
    width:100px;
    height:100px;
    background:red;
    transition:width 2s;
    -moz-transition:width 2s; /* Firefox 4 */
    -webkit-transition:width 2s; /* Safari and Chrome */
    -o-transition:width 2s; /* Opera */
    }

    div:hover
    {
    width:300px;
    }
    </style>

但是有谁知道使用点击而不是悬停来做到这一点的方法吗?不涉及 JQuery?

谢谢!

最佳答案

你可以这样写:

CSS

input{display:none}
.ani
    {
    width:100px;
    height:100px;
    background:red;
    transition:width 2s;
    -moz-transition:width 2s; /* Firefox 4 */
    -webkit-transition:width 2s; /* Safari and Chrome */
    -o-transition:width 2s; /* Opera */
    display:block;
    }
input:checked + .ani{width:300px;}

HTML

<input type="checkbox" id="button">
<label class="ani" for="button"></label>

检查这个http://jsfiddle.net/nMNJE/

关于CSS3 过渡 : is there an on click option without using JQuery?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11166580/

相关文章:

html - 试图在右侧获得与左侧相同的效果 [css3 ribbons]

javascript - 在深色模式下切换 Logo 颜色问题

javascript - 单击动态修改的 Button?

jquery - 菜单项鼠标悬停时淡入有效,但淡出无效

javascript - css/javascript : checking pixels of image where hover effect is triggered

html - 如何将表单输入和标签放在一起?

javascript - 在使用 Freeze Table jQuery 插件的 HTML 表格的左粘列中遇到奇怪的填充问题

javascript - 在两个功能之间切换

javascript - Internet Explorer 10/Windows Phone 8 如何区分点击和触摸事件

html - 悬停框位置问题