我在某种程度上理解:active
状态,但我不知道如何通过点击(不保留)来转换box1
。相反,要转换我需要点击并按住框在整个转型期间。
https://jsfiddle.net/kzmhtkog/4/
.wrap {
width: 100%;
height:400px;
overflow:hidden;
}
#box1 {
background-color:red;
text-align:left;
cursor: pointer;
-webkit-transition: width 1s;
transition: width 1s;
}
#box1:active {
width: 100%;
background-color: red;
}
.floatleft {
float:left;
width: 33.33%;
background-color: black;
height: 400px;
}
<div class="wrap">
<div class="floatleft" id="box1">
</div>
</div>
答案 0 :(得分:1)
你必须使用jQuery或javascript。
$('#box1').click(function() {
$(this).toggleClass('active');
});
.wrap {
width: 100%;
height:400px;
overflow:hidden;
}
#box1 {
background-color:red;
text-align:left;
cursor: pointer;
-webkit-transition: width 1s;
transition: width 1s;
}
#box1.active {
width: 100%;
background-color: red;
}
.floatleft {
float:left;
width: 33.33%;
background-color: black;
height: 400px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrap">
<div class="floatleft" id="box1">
</div>
</div>