Use CSS Classes to Reuse and Override Styles

Jhey Tompkins
InstructorJhey Tompkins
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

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.

egghead
egghead
~ 24 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today