0

How can I change the symbol to "V" when click the widget title, after click back the widget title will change back the symbol ">".

image before click: link

This is my css that added after the widget title.

.widgettitle a::after {
    content: " >";
        font-size:16px;
        color:#d3db2c!important;
}
xuezheng
  • 21
  • 1
  • 7
  • I think this cannot be done in pure CSS. You either need to add a hidden `` to your HTML and then add some pretty fancy CSS rules, or (probably best solution) to use JavaScript. – alx May 24 '18 at 11:41
  • Hi VXp, it is a collapsible widget like the drop down menu. – xuezheng May 24 '18 at 12:07
  • Possible duplicate of [css rotate a pseudo :after or :before content:""](https://stackoverflow.com/questions/9779919/css-rotate-a-pseudo-after-or-before-content) – Mehrad May 24 '18 at 12:08

4 Answers4

1

    $(".greater").click(function(){
var test = $( this ).hasClass( "greater" );


if(test){
$( this ).removeClass( "greater" );   
  $( this ).addClass( "less" );   
}else{
  $( this ).removeClass( "less" );   
  $( this ).addClass( "greater" );   
  
}
});
.widgettitle .greater::after {
 content: " >";
 font-size:16px;
 color:#d3db2c!important;
}

.widgettitle .less::after {
 content: " v";
 font-size:16px;
 color:#d3db2c!important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<div class="widgettitle">
 <a href="#" class="greater">test</a>
</div>
Vishal Panara
  • 233
  • 3
  • 15
1

:active mean when click on a

.widgettitle a::after {
    content: " ►";
}
.widgettitle a:active::after {
    content: " ▼";
        font-size:16px;
        color:black!important;
}
<div class="widgettitle">
<a href="#">back</a>
</div>

To your comment

Can make it after click it will remain ▼, then click back will change back to ►

Use toggle class

.widgettitle a::after {
    content: " ►";
}
.widgettitle .toggle::after {
    content: " ▼";
        font-size:16px;
        color:black!important;
}
<div class="widgettitle">
<a href="#" onclick="this.classList.toggle('toggle');">back</a>
</div>
לבני מלכה
  • 15,925
  • 2
  • 23
  • 47
1

You've to use checkbox hack to achieve this in pure CSS:

.link {
  text-decoration: none;
}
.checkbox {
  display: none;
}

.link:after {
  content: '►';
  margin-left: 5px;
  display: inline-block;
}

.checkbox:checked ~ .link:after {
  transform: rotate(90deg);
}
<div class="link-container">
    <label for="checkbox-1">Click me</label>
    <input type="checkbox" id="checkbox-1" class="checkbox">
    <a href="#" class="link"></a>
</div>
Rajender Joshi
  • 4,155
  • 1
  • 23
  • 39
0

Another solution with JavaScript. Hope its help.

.widgettitle a::after {
     content: " >";
     font-size:16px;
     color:#d3db2c!important;
    }

    .newclass a:focus::after {
       content: "v";
    }
<div id="wg" class="widgettitle">
     <a id="aid" href="#">test</a>
</div>

<script>

var aid = document.getElementById("aid");
var wg = document.getElementById("wg");
aid.onclick = function(){
 wg.classList.toggle("newclass");
}

</script>
Friday Ameh
  • 1,664
  • 1
  • 10
  • 15