Can I make this SCSS code functional within CSS styling?

I stumbled upon this interesting +/- toggle button design on a codepen here

The only problem is that the CSS processor used in the codepen is SCSS, and when I try to convert it to CSS, it stops functioning.

My website project is using CSS, and when I try to integrate the CSS code from the codepen, my VS Code editor starts flagging errors. Is there a way for me to make this work with regular CSS?

.closed {
  .vertical {
    transition: all 0.5s ease-in-out;
    transform: rotate(-90deg);
  }
  .horizontal {
    transition: all 0.5s ease-in-out;
    transform: rotate(-90deg);
    opacity: 1;
  }
}

.opened {
  opacity: 1;
  .vertical {
    transition: all 0.5s ease-in-out;
    transform: rotate(90deg);
  }
  .horizontal {
    transition: all 0.5s ease-in-out;
    transform: rotate(90deg);
    opacity: 0;
  }
}

.circle-plus {
    height: 4em;
    width: 4em;
    font-size: 1em;
    opacity: .7;
}

.circle-plus .circle {
    position: relative;
    width: 2.55em;
    height: 2.5em;
    border-radius: 100%;
    border: solid .5em #DFDAD7;
}
.circle-plus .circle .horizontal {
    position: absolute;
    background-color: red;
    width: 30px;
    height: 5px;
    left: 50%;
    margin-left: -15px;
    top: 50%;
    margin-top: -2.5px;
}
.circle-plus .circle .vertical {
    position: absolute;
    background-color: red;
    width: 5px;
    height: 30px;
    left: 50%;
    margin-left: -2.5px;
    top: 50%;
    margin-top: -15px;
}

Any suggestions or help would be greatly appreciated. Thank you!

Answer №1

If you want to streamline your workflow, consider converting sass into css manually or utilizing an online compiler as I have done in the past.

Outcome

.closed .vertical {
  transition: all 0.5s ease-in-out;
  transform: rotate(-90deg);
}
.closed .horizontal {
  transition: all 0.5s ease-in-out;
  transform: rotate(-90deg);
  opacity: 1;
}
.opened {
  opacity: 1;
}
.opened .vertical {
  transition: all 0.5s ease-in-out;
  transform: rotate(90deg);
}
.opened .horizontal {
  transition: all 0.5s ease-in-out;
  transform: rotate(90deg);
  opacity: 0;
}
.circle-plus {
  height: 4em;
  width: 4em;
  font-size: 1em;
  opacity: 0.7;
}
.circle-plus .circle {
  position: relative;
  width: 2.55em;
  height: 2.5em;
  border-radius: 100%;
  border: solid 0.5em #DFDAD7;
}
.circle-plus .circle .horizontal {
  position: absolute;
  background-color: red;
  width: 30px;
  height: 5px;
  left: 50%;
  margin-left: -15px;
  top: 50%;
  margin-top: -2.5px;
}
.circle-plus .circle .vertical {
  position: absolute;
  background-color: red;
  width: 5px;
  height: 30px;
  left: 50%;
  margin-left: -2.5px;
  top: 50%;
  margin-top: -15px;
}

To further enhance efficiency, setting up a preprocessor that compiles scss to css through bundlers is recommended for larger websites where organizing styles becomes necessary.

Answer №2

In the response given by Min Lee, it is suggested to simply convert SCSS to CSS. However, understanding the distinction between the two is important as the conversion process is relatively straightforward.

The key step is to eliminate any nested rules that are not compatible with CSS.

For example, transform this SCSS code:

.closed {
  .vertical {
    transition: all 0.5s ease-in-out;
    transform: rotate(-90deg);
  }
  .horizontal {
    transition: all 0.5s ease-in-out;
    transform: rotate(-90deg);
    opacity: 1;
  }
}

.opened {
  opacity: 1;
  .vertical {
    transition: all 0.5s ease-in-out;
    transform: rotate(90deg);
  }
  .horizontal {
    transition: all 0.5s ease-in-out;
    transform: rotate(90deg);
    opacity: 0;
  }
}

To this CSS format:

.closed .vertical {
  transition: all 0.5s ease-in-out;
  transform: rotate(-90deg);
}
.closed .horizontal {
  transition: all 0.5s ease-in-out;
  transform: rotate(-90deg);
  opacity: 1;
}
.opened {
  opacity: 1;
}
.opened .vertical {
  transition: all 0.5s ease-in-out;
  transform: rotate(90deg);
}
.opened .horizontal {
  transition: all 0.5s ease-in-out;
  transform: rotate(90deg);
  opacity: 0;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Translate3d increases the whitespace towards the end of the page

After implementing a smooth scroll on my webpage using transform translate3d, I encountered an issue. The translate3d function seems to be adding extra space at the end of the document, as illustrated here: https://codepen.io/anon/pen/WEpLGE I suspect the ...

IE compatibility problem with the alignment of input group buttons and textboxes in Bootstrap v4

Encountering an issue with input group in IE while using bootstrap v4, working fine in Chrome. Specifically using IE 11 Here is my plunkr: input group bootstrap v4 Chrome display: https://i.sstatic.net/yXtEW.png IE display: https://i.sstatic.net/WiRz ...

What is the best way to alternate between two CSS stylesheets when using jQuery-UI?

Just getting started with jQuery and javascript and decided to test out 2 different jQuery-ui stylesheets in a simple .html file. The goal is to have the example dialog open with the "flick" stylesheet and the datepicker within the dialog open with the "u ...

selecting a style with "display: block;" using Selenium WebDriver

I'm having trouble clicking on an element with the style "display: block;" and can't seem to make it work. Here is the sample html snippet <div class="fl f18 dtoggler pointer underline some-padding new_data_entry" data-div-id="eBWJcg" data-d ...

When utilizing SVG 'use' icons with external references, Chrome may fail to display icons when viewing an HTML file locally

I'm currently experimenting with using SVG icons, following the guide found at https://css-tricks.com/svg-use-with-external-reference-take-2/ Here's how it appears: <!-- EXTERNAL reference --> <svg> <use xlink:href="sprite.svg# ...

Having unexpected outcomes with CSS and fonts compared to what is seen on live websites

Lately, I've been encountering a persistent issue - the fonts on many websites have a certain quality that I find difficult to articulate. It's like they possess a boldness, clarity, and sharpness that gives them a powerful presence. Take for ins ...

Using SCSS based on the browser language in Angular: A Step-by-Step Guide

Is there a way to implement SCSS that is dependent on the user's browser language? When I checked, I found the browser language specified in <html lang = "de"> and in the CSS code as html[Attributes Style] {-webkit-locale: "en&quo ...

Is it possible to replace a css rule with a different one?

Seeking help with CSS. I am currently dealing with older code that has its own set of css rules linked to a 'css manager'. Now, I want to integrate jQuery UI for its appealing dialogues and features. My inquiry is as follows: There is a css ru ...

I am experiencing issues with the functionality of the submit and clear buttons on my form

Hello, I am a beginner in the world of coding and recently encountered an issue while working on a project. I attempted to create a form with both submit and reset buttons, but unfortunately, the form does not seem to be functioning properly on either de ...

The image does not appear as expected in Lightgallery

I am in search of a gallery that features thumbnails, opens up upon clicking on an image, and includes captions. Although lightgalleryjs meets most of my requirements, it fails to render the actual images, showing a black screen overlay instead. Code: In ...

Tips for activating a dropdown in Bootstrap 4

I am currently working on a dropdown menu where I want to set an active state upon a click. The active class is added successfully when a link is clicked, but the issue arises when trying to remove the active class when another link is clicked. I only want ...

Having trouble with applying CSS conditionally in React JS with Typescript?

I'm currently facing an issue with my code where I want the Box to stay highlighted with a black border when clicked. Here's the snippet: interface BigButtonProps { onClick(): void; Title: string; Description?: string; startIcon?: R ...

The AngularJS modal feature from ui.bootstrap.modal is currently experiencing technical difficulties

I need help implementing an AngularJS Modal (ui.bootstrap.modal) in my project. I want a large modal to pop up whenever a button on my page is clicked. I have tried using bootstrap codes but it doesn't seem to be working. Can someone assist me with th ...

The height of the footer element is gradually dwindling

Have you ever wondered why a footer element mysteriously shrinks in height when the browser window is resized? I attempted to create a fiddle with my code, but unfortunately, it's not replicable on JSFiddle so I won't be sharing it. This is how ...

OO Design for CSS Style Elements

I'm curious about the most effective way to implement objective-oriented CSS for quick and clean reuse of components. Scenario 1: HTML: <button class="button button-submit">Submit</button> CSS: .button { /* basic styles */ } .button ...

Is there a way to update the styling of specific sections of an input field as the user enters text in React?

Just like in most markdown editors, I am looking to enable the ability to modify parts of an input field as the user enters text. For instance: When the user types "_above_", as soon as the second underscore is typed, the text should be styled accordingly ...

Shifting hues of dots within a grid according to the passing of time

As a newcomer to the world of coding, I have conceptualized an idea for a visually appealing clock. My goal is to visually represent the passage of time throughout the day. To achieve this, I have devised a grid system where each dot on the grid represents ...

Nav bar displaying CSS and HTML <a> tags

I am encountering a new issue that I have not faced before and I am seeking some guidance on it. The problem is with a navigation bar displayed at the top of a webpage. When the code is executed, the browser automatically adds 'a' tags which disr ...

How to manipulate wrapping behavior in flexbox

My flex container holds three divs, arranged in two rows: First row: One div with a fixed width Another div that should stretch to fill the remaining space Second row: Just one item However, the first div stretches to 100% width and pushes the seco ...

Is there a way to incorporate two Bootstrap navbars on a single page that are of varying heights?

Utilizing Bootstrap 3.0 with dual navbars on a single page that adjust in height using the same variable for both .navbar blocks. Despite attempting to incorporate an additional class to alter the height of the initial navbar, it remains unaffected. Check ...