Stylish Sass with Keyframes

I'm attempting to generate a rotating circle using css keyframes, but I'm encountering challenges in making it work with Sass.

Here is the HTML code snippet:

<div class="content">
    <h1 class="h1">Experimenting with keyframes</h1>
    <div class="circle"></div>
</div>

And this is the corresponding Sass code:

.content{
        display:block;
        position: relative;
        box-sizing:border-box;

        .circle{
            width: 220px;
            height: 220px;
            border-radius: 50%;
            padding: 10px;
            border-top: 2px solid $pink;
            border-right: 2px solid $pink;
            border-bottom: 2px solid $pink;
            border-left: 2px solid #fff;
            -webkit-animation:spin 4s linear infinite;
            -moz-animation:spin 4s linear infinite;
            animation:spin 4s linear infinite;
        }

        @-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
        @-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
        @keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }
    }

I rely on Prepros for compiling my Sass and the generated output showcases the classes inside the keyframes as follows:

@-moz-keyframes spin {
  .lesson-page .content 100%  {
    -moz-transform: rotate(360deg);
  }
}
@-webkit-keyframes spin {
  .lesson-page .content 100%  {
    -webkit-transform: rotate(360deg);
  }
}
@keyframes spin {
  .lesson-page .content 100%  {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}

Answer №1

It seems that this issue is specific to Sass 3.3. The @keyframes declarations are not properly rising to the top as expected. If upgrading to version 3.4 is not feasible, consider avoiding nesting your keyframes.

.content{
    display:block;
    position: relative;
    box-sizing:border-box;

    .circle{
        width: 220px;
        height: 220px;
        border-radius: 50%;
        padding: 10px;
        border-top: 2px solid $pink;
        border-right: 2px solid $pink;
        border-bottom: 2px solid $pink;
        border-left: 2px solid #fff;
        -webkit-animation:spin 4s linear infinite;
        -moz-animation:spin 4s linear infinite;
        animation:spin 4s linear infinite;
    }
}

@-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
@-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
@keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }

Further reading: How to make a Sass mixin declare a non-nested selector on base level?

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

Express causing textarea in http form to have empty req.body

Here is a form for users to upload a file and submit text: form(action='/createpost' enctype="multipart/form-data" method='post' id="imgForm") input(type='file' name='imgPath' size = "60") br textarea(na ...

How can I use CSS to ensure that both cards and images are equal in size?

I am currently utilizing react, with Material-ui being used for the Cards. For the layout, I have implemented CSS Grid Layout for the Grid system. Presently, the structure looks like this: https://i.stack.imgur.com/0FDyY.png However, my desired outcome i ...

Prevent the bootstrap header in a table from scrolling by enclosing it in

I am encountering an issue with fixing the headers of multiple tables in a page within their dedicated divs. Despite trying various methods, I haven't been successful as the fixed header overflows the div. I want to confine it within the div. Additio ...

Troubleshooting: Why isn't my jQuery Click Event functioning in Mozilla but working perfectly fine in

While I know this question has been asked before, I can't seem to locate the posts I remember reading about it. I apologize for any duplication, but I am trying to implement a "click anywhere BUT here to close element overlay" effect on my personal we ...

Limit pasted content in an Angular contenteditable div

Is there a way to limit the input in a contenteditable div? I am developing my own WYSIWYG editor and want to prevent users from pasting content from external websites and copying styles. I want to achieve the same effect as if the content was pasted into ...

The art of layering images: How to stack one image on top of another

I am in the process of trying to place a logo on top of an image, but I have been unsuccessful so far. Rather than overlapping, the second image is appearing next to the first one. Can you help me figure out how to solve this issue? This is for a website ...

Is a persistent left border / divider only on the even-numbered items in the list?

I have a layout of list items arranged in 2 columns, separated by a bottom margin after every 'row' of 2 items. While it's simple to add a left border to every even list item... I am curious if it's achievable to extend the border so ...

Issues concerning the customization of error messages in forms are arising

Summing it up, upon form submission, error messages appear beneath each input field with invalid values. Utilizing Zend_Form results in the following markup: <form enctype="application/x-www-form-urlencoded" method="post" action="/auth/register">< ...

How to create a personalized attribute for a form in Yii2

Currently, I am working on an active form and I would like to include a custom attribute. This is a standard form field: <?= $form->field($model, 'password')->textInput() ?> I want it to appear as: <label class="input"> < ...

Experience the illusion of three-dimensional depth with SVG light and shadow effects

I am trying to achieve a 3D effect on an SVG by adding a light source at the top and left border, and a shadow on the bottom and right border. Here is an example: #div1 { background: #ddd; } #div1, #div2, #div3 { width: 100px; height: 100px; po ...

md-auto-complete problem with search query

Hi there, I am currently facing an issue with my md auto complete search box. The problem arises when I type a name and the search function is triggered. This search function calls an API, but in the meantime, it returns a null array to the auto complete f ...

Having Trouble Operating Virtual Tour in Flash

I recently used a third-party software to create a virtual tour for my client's website. The virtual tour works perfectly fine on its own, as you can see here: However, when I tried to include the virtual_tour.html page on the index page of the websi ...

The width of the Div element is not determined by the parent CSS grid, leading to a lack of ellipsis

I am working on a grid layout where each column contains a div with text. My goal is to have the text show ellipsis when it overflows the column, even though the number of columns is random. I attempted to use the following CSS for the text-containing div ...

Updates made to CSS are not appearing on the Joomla site

My website is based on Joomla and has been functioning well since it was created. However, recently I have noticed that any CSS changes made in the files are not showing up on the site. I have tried clearing the cache and viewing it from different ISPs, ...

Ensure that the default value in the text box remains unchanged until new text is input by utilizing jQuery

Can you please review my code snippet on http://jsfiddle.net/7995m/? The issue I'm facing is that the default text in the text box disappears as soon as it's clicked. What I want is for the default text to remain until the user starts typing. Her ...

Is it possible to enlarge a div using "display: table-cell" property when clicked on?

There are various components displayed on my webpage: I require all components to have a minimum height of 150px. If the height is less than 150px, I want to vertically center their text. In case the height exceeds 150px, I aim to truncate the text at 15 ...

Tips for implementing automatic line wrapping in a PDF document using React-PDF

I am experiencing an issue with a PDF rendering where very long words are not wrapping onto a new line, instead overflowing the container and disappearing off the page. Below is the setup causing this problem. The styles are listed followed by the actual ...

Enabling or Disabling Inputs in Angular

I'm looking to customize my form behavior in a specific way - when I click on the modify button, I want only one line to be modified instead of all three. How can I achieve this? Images : edit save app.component.html : <table mat-table [dataSourc ...

Steps for eliminating redundant lines in a CSS drop-down navigation bar

When looking at the following CSS code, I noticed that the bottom and top borders seem to overlap, creating a thick line. I'm having trouble figuring out how to remove it. Any suggestions or advice would be greatly appreciated. Thank you! HTML Code: ...

CSS selectors target all elements within a specific div container

Is there a way to select all checkbox input elements that are not contained within a div class that begins with 'xyz_' using CSS? If so, how can this be achieved with a CSS selector? ...