Use CSS Classes to Reuse and Override Styles

Jhey Tompkins
InstructorJhey Tompkins
Share this video with your friends

Social Share Links

Send Tweet

In this lesson, we create a second lens for our Egghead spectacles. These are a mirror image of each other. Instead of writing out the styles again, we can reuse the styles and make use of the specific class to override the positioning and transform in order to mirror the right lens.

Jhey Tompkins: [0:00] Now we're ready to style the second lens, our right lens. It needs to be on the right side of our container. We can use a value of right: . Now our transform value needs to change. There we will define a rotation of -10deg. We also need to rotate the element on the Y axis to mirror it.

[0:23] Our rotation isn't quite right, so maybe +10deg will work. And it does. Because by default our lens is styled to be the left lens, we don't need to use the left lens class. The right lens class we can use to overwrite the shared styles and position our right lens accordingly.

[0:41] In review, to style the second lens, or the right lens, we've used the shared styles from the specs__lens class, but we overwrite the positioning and the transform to get the desired result.