我很难从这个问题中获得模糊且不想要的答案,所以我决定发表一个清晰的问题来概述我面临的问题。
我正在使用的代码如下:
我正在使用的代码如下:
.flipClass {
font-size: Large;
background-color: #4399CD;
color:#fff;
text-align: left;
}
.flipClass:active{
background:#fff;
color:#4399CD;
cursor:pointer;
transition:all .1s ease-out;
}
.flipClass:active:before {
content:'\f102';
font-family:FontAwesome;
font-style:normal;
font-weight:normal;
text-decoration:inherit;
padding-left:6px;
padding-right:8px;
transition:all .3s;
}
我点击元素后,如何获取由.flipClass:active定义的CSS样式?目前,它仅在短暂的时间内处于活动状态。
请查看下面给出的片段:
$("div[id^=flip]").click(function() {
$(this).next("div[id^=panel]").stop().slideToggle("slow");
});
.panelClass,
.flipClass {
padding: 5px;
padding-left: 15px;
border: solid 1px #c3c3c3;
}
.flipClass {
font-size: Large;
background-color: #4399CD;
color: #fff;
text-align: left;
}
.flipClass:active {
background: #fff;
color: #4399CD;
cursor: pointer;
transition: all .1s ease-out;
}
.flipClass:active:before {
content: '\f102';
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
text-decoration: inherit;
padding-left: 6px;
padding-right: 8px;
transition: all .3s;
}
.panelClass {
padding: 30px;
padding-top: 10px;
display: none;
background-color: #F3F5F6;
color: #000;
}
.flipClass:before {
content: '\f107';
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
text-decoration: inherit;
padding-left: 6px;
padding-right: 8px;
transition: all .3s;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" />Currently, the .flipClass:active CSS style sheet is working only for a brief moment (precisely until the duration of the mouseclick and maybe some small offset). Click and HOLD mouseclick when clicking on .flipClass to see the effect. I want it to stay!
<div class="flipClass" id="flip1">FIRST HEADING</div>
<div class="panelClass" id="panel1">How to keep the first heading 'active' when this panel is showing? If I could figure that out, I could change the arrow to a pullup arrow too :3</div>
<div class="flipClass" id="flip2">SECOND HEADING</div>
<div class="panelClass" id="panel2">If both Headings have been clicked, this Heading and any other heading that were clicked should also be active (or atleast remain in the CSS state defined by .flipClass:active here)</div>
目前,.flipClass:active CSS样式表仅在短暂的时刻(准确地说,直到鼠标点击的持续时间和一些小偏移量)内起作用。我需要一种方法,在flipClass被点击后始终保持活动状态。我是否使用了不适当的伪选择器?
有什么解决方法吗?或者有没有其他专门用于此目的的伪选择器?可以给个例子吗?
:focus
代替。 - Azizcheckbox
和相应的label
。将标题作为label
,将:active
样式绑定到:checked + .flipClass
上。额外的好处是,你还可以通过:checked + .flipClass + .panelClass
将你的手风琴移动到 CSS 中。顺便说一下,给类名后缀加上 "Class" 有点极度冗余。 - abluejelly:focus
只有在用户点击其他内容之前才有效,这不是他想要的行为。他希望样式能够根据面板是否显示保持不变,或者至少保持最近打开的面板处于:active
状态。 - abluejelly:target
实现它;唯一需要添加的是需要一个自指的锚点a
。 - abluejelly