How to Use SCSS %placeholder in Real World

Handling CSS properties that you can combine and reuse in project libraries that you don’t need to rewrite again.

Code Road
2 min readMar 26, 2020
Placeholder
Photo by Kelly Sikkema on Unsplash

Placeholder in web development is very useful for your front end web development workflow. Placeholder help you to be more productive without rewriting properties all over again that you need in your CSS library.

SASS / SCSS has a placeholder function that you can use in your projects. You can customise your needs and made a small library out of it. Include placeholders in your SCSS and use them every time you want it in your project. If you unfamiliar with SASS / SCSS, you can read my post about it in here and here. In this next post, I will show you how to use %placeholder in real world of front end development.

HTML Setup :

HTML setup on SCSS %placeholder

SCSS Placeholder setup :

SCSS %placeholder setup with default variables

CSS / The result :

CSS result on SCSS %placeholder
Result on placeholder basic
CodePen on SCSS placeholder

Placeholder could be used in any of CSS Properties such as :hover, ::before, ::after and many other.

HTML Setup for SCSS %placeholder in :hover properties :

HTML for SCSS %placeholder on :hover property

SCSS setup %placeholder in :hover properties :

SCSS %placeholder setup on :hover property

CSS result %placeholder in :hover :

CSS Result on SCSS %placeholder

HTML Setup for %placeholder on ::before and ::after property :

HTML Setup for %placeholder on ::before and ::after property

Using SCSS %placeholder in ::before and ::after property :

SCSS %placeholder in ::before and ::after property

CSS result on our %placeholder on ::before and ::after property :

CSS result on our %placeholder on ::before and ::after property

Result on our SCSS %placeholder final project :

Image before, after and hover scss placeholder
Image result on ::before, ::after and :hover SCSS placeholder
CodePen on ::before, ::after and :hover with SCSS placeholder

I use placeholder a lot in all my projects. Placeholder is very helpful for any case that no need to rewrites CSS properties all over again. Thank you for stopping by and reading this. Feel free to comments and contact me regarding this post.

Reference :
https://sass-lang.com/documentation/style-rules/placeholder-selectors

--

--

Code Road
Code Road

Written by Code Road

I write topics such as React/NextJS, Vue/NuxtJS, GraphQL, Laravel, TailwindCSS, Bootstrap, SEO, Headless CMS, Fullstack, and web development.

No responses yet