Edited on May 27th 2022
Toggles and accordions. First, read up on when they’re useful for UI, and when they are not.
So for this tutorial, let’s assume using them are helpful for the page.
Somehow, they get real boring quickly, and they’re not always the coolest.
Check out the toggle on the demo site. The icon is different, plus check out the sweet animation on the toggles. (The accordions are slightly different)
The snippet
Here, copy this and paste it somewhere that custom code is welcomed.
.et_pb_toggle_open .et_pb_toggle_title:before {
content: "\4c";
color: black;
font-size: 36px;
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
-ms-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-o-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
.et_pb_toggle_close .et_pb_toggle_title:before {
color: black;
font-size: 36px;
content: "\4c";
-webkit-transition: all 0.5s ease-in-out;
-moz-transition: all 0.5s ease-in-out;
-o-transition: all 0.5s ease-in-out;
-ms-transition: all 0.5s ease-in-out;
transition: all 0.5s ease-in-out;
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
-ms-transform: rotate(0deg);
transform: rotate(0deg);
}
Some explanations
What we’re using here is a pseudo element. Simply put, it’s something you attach before or after an element to make it display something extra. It’s really useful in many ways of styling things, and here, the toggle gets some.
One styles the open toggle, the other one styles the closed toggle.
- color: black; -> The color of the icon
- font-size: 36px; -> It’s gotta be a certain size, otherwise it’s too small.
- content: “\4c”; -> This is based off of the Elegant Themes Iconset. You can change this if you want. To learn how to add more icons, check out an example of the method here.
- transition: all 0.5s ease-in-out; -> a bunch of transitions with vendor prefixes. You can change the 0.5s from half a sec to something else if you want.
- transform: rotate(45deg); -> a bunch of transforms with vendor prefixes. You can probably see that this rotates the icon by 45 degrees.
So yeah, change the values to get what you want. Have fun!
[sc name=”learn css”]
[sc name=”podcast”]
zea says:
Hi there, I send a message to the link you’ve posted. I’m happy that you reply on my post.
zea says:
Hi there!
I really like the toggle icon when you click it it turns out to X., but I can’t add that on the website of my client. Can you help me please?
PK says:
Hi Zea, could you please post a URL, or send me an email the URL via http://almostinevitable.com/contact-me/ and I can have a look!
Thanks