Sponsored

Not the solution you were looking for?

Hope you got some time to read my previous tutorials on 3D Cube rotation and Photo cube gallery. Today I thought of writing few CSS effects for Inline Anchor texts using pseudo-elements, SVG and data attribute. For most part of the demo, we will be using an anchor tag and apply some styles or effects to its pseudo-elements such as ::before and ::after. For the 3D effect, we will be using data attribute and SVG for few effects. The effects varies from FadeIn, Scale Up, Slide Left, Slide Right to 3D rotation. The sad thing is, I’ll not be able to explain all the effects in this tutorial, but yes the demo and the source download will feature all those.

Before we get into the tutorial, please remember that these codes may not work on all browsers. For instance, most of the CSS animation properties are not supported on IE8 and below. Also, few browsers need vendor specific prefixes to be added. If I have missed, you may add it.

As I told earlier, we will be using CSS pseudo elements ::before and ::after. So let me just brief about those.

::before pseudo element

::before pseudo element is used to add some content before the existing content of an element. For example,

#classID::before{
content: '#';
}

::after pseudo element

::after pseudo element is used to add some content after the existing content of an element. For example,

.className::after{
content: '%';
}

Important note here – the pseudo elements MUST have content property. You can choose to have an empty value for the content property, but you cannot just ignore it.

Lookout for the transform property translateY. Since our aim is to create a Slide Up effect (I mean, the action should be performed on Y-axis), we use translateY method. It means, set the transformation to start from 98% at Y-axis ::before hovering. When hovered? Stop the transformation at 0% at Y-axis (translateY(0%))

If you have read my previous tutorial on 3D cube rotation, then you must have read about perspective. The perspective property is normally applied for the parent and the child element gets that perspective view. Here, we consider the anchor element as the perspective wrapper, so we apply 3D rotation to ::before pseudo-element. It means, we will perform a rotation of 90 degrees and make it invisible before hovering. When hovered, we bring the rotation back to 0 degrees. What you get? A flip effect.

Note: The demo has not been tested on all browsers. In case if it doesn't work on any specific browser, then you may have to add vendor specific prefix. You are free to download the code and play with it!

Credits: This tutorial would not have been possible without the help from Mary Lou