Is it possible to incorporate variables within literal CSS in Stylus?

My Stylus function has the following structure:

// Convenient way to create a top-down gradient background color
td_gradient(color1, color2)
    background-color (color1 + (color2 - color1) / 2)
    background -webkit-gradient(linear, 0% 0%, 0% 100%, from(color1), to(color2))
    background -webkit-linear-gradient(top, color1, color2)
    background -moz-linear-gradient(top, color1, color2)
    background -ms-linear-gradient(top, color1, color2)
    background -o-linear-gradient(top, color1, color2)
    @css
    {
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=color1, endColorstr=color2);
    }

To avoid causing Stylus to crash, I had to place the Internet Explorer gradient style within the literal css scope @css. This prevents Stylus from incorrectly interpreting the color1 and color2 variables within the css scope, which would break the style.

Is there a way to allow the css scope to properly parse variables? Alternatively, is there a method to include the filter style in Stylus without relying on the literal css scope?

Answer №1

One method to accomplish this is:

Applying a filter s('progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorstr=%s, EndColorstr=%s)', color1, color2))

However, I highly recommend exploring nib, created by TJ. Specifically, he has constructed a mixin that automatically generates a gradient image in png format and encodes it into the stylesheet using base64. The only stipulation is that you must specify the height (or width for horizontal gradients), which should be suitable for your td elements.

UPDATE: A more concise approach:

Applying the filter 'progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorstr=%s, EndColorstr=%s)' % (color1 color2)

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

Challenges with the Placement of Buttons

I am facing an issue with the code below: document.addEventListener("DOMContentLoaded", function(event) { // Select all the read more buttons and hidden contents const readMoreButtons = document.querySelectorAll(".read-more"); const hiddenConten ...

I encountered an issue after initiating my React app with the command "npx create-react-app my-app" as running npm start resulted in an ELIFECYCLE error. How should I proceed to resolve

I've been working my way through the official React tutorial and decided to use my own text editor instead of the suggested one. I followed all the instructions until it came time to create my app using "npx create-react-app my-app". However, when I t ...

Is Apache required for running NodeJs?

Recently, I set up a web project on my local machine following a tutorial. With the help of XAMPP, I was able to install MySQL and Apache to run my Node.JS backend. Now, I'm looking into hosting the project on an external server to make it accessible ...

Having trouble linking nodejs and mysql within the same docker container

Recently I've started using Docker and attempted to run my Node.js Express application inside it. I managed to successfully install dependencies using a shell script, but encountered an issue where I couldn't connect to MySQL at the end. In my ...

`Looking for information on configuring express.js settings?`

I feel a little embarrassed to have to ask, but does anyone know where I can get details on the settings available in express.js? The documentation mentions using app.set(name, setting) to define a setting for a specific name, but I'm having trouble l ...

Enhance the appearance of radio buttons using CSS and incorporate images to create a

Is there an easy and straightforward method to customize radio buttons using only CSS, allowing me to click on an image instead of a traditional bullet point? For example, like thumbs up/thumbs down. I have two radio buttons that need to track which one i ...

The Socket.io Namespace does not support the adaptor method

I am currently working on an application where I need to create dynamic namespaces. Whenever a new namespace is created, I attach a redis-adapter to it for scalability reasons. However, when implementing this process, I encounter the following error: var ...

Adjustable dimensions for a collection of squares based on screen size

I am currently designing a grid composed of 1:1 squares and allowing the user to continually add more squares. My main goal is to ensure that the size of each square maintains its aspect ratio while being able to resize accordingly. The challenge lies in k ...

Control the start and stop of an Express.js app in Node.js using PHP

I'm currently developing a web service using express.js in the node.js npm environment. In order to deliver this project to my client, I need to create a controller file that allows me to start and stop the server without having to use the command pr ...

Customizing SharePoint Web Part Styles with CSS: Header Alignment Issue with Body_TEXT

I am currently working on branding a SharePoint website and have encountered an issue with aligning background colors for the title area and body of some web parts. Despite applying background colors, the alignment between the title and body areas is off ( ...

Positioning two buttons side by side in separate columns on the same horizontal alignment

My objective is to arrange these two buttons horizontally on the same level with the help of bootstrap. <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href ...

Inconsistency in css asset URLs across various pages discovered while working with Rails

When using assets stylesheet to load a CSS file, I noticed that it only loads on the index page. Upon inspecting with F12, the console shows the URL for other pages as well, which appends "/cloths" to the asset path. I am currently utilizing the default la ...

What is the best way to deliver an image to a client using Express and Node.js?

I've been working on a straightforward Express API that integrates with the Google Places API. My goal is to send place photos to the client, but I've hit a roadblock. Here's an example response from the Google Places API: Within the respon ...

Harmonizing controls with ASP.NET using CSS styling

I have created a web form application which is displayed in the image provided. However, when I view the same page in the browser, the output appears completely misaligned despite the designer file being perfect. The markup for this form is quite lengthy ...

Communicate with a channel through a function

In my code, I have set up an event handler for the ready event. File: ready.js const { Events } = require('discord.js'); const db = require("../config/database"); const itemdb = require("../config/itemdb"); const items = requi ...

Focus border radius for anchor tag image

I am trying to implement the following CSS: .sky:focus {border-radius: 25px; border: #000 solid 1px; outline: none} And my HTML looks like this: <a class='sky' href='#'><img src='cloud.jpg'></a> I want a 25 ...

Tips for properly showcasing images on a webpage after ensuring all other content has loaded

Is there a way to have an image load last on a webpage after all other content has been loaded? I have an image that is retrieved from a database when a button is pressed, but I would prefer for the entire page to load first and then display the image. C ...

Effortlessly set up FFMPEG on Google Compute Engine with Debian Wheezy 7.8

I am managing a Google Cloud Compute Engine project and need to automate the installation of FFMPEG on all instances. I am utilizing the node.js module https://github.com/fluent-ffmpeg/node-fluent-ffmpeg for video watermarking and thumbnail generation on ...

Seeking assistance in creating custom tabs for integration with a jQuery tabs plugin

Attempting to navigate the world of CSS as a newbie, I find myself struggling with creating tabs. Our current tab setup can be viewed here, but unfortunately, these tabs are created using an unattractive <table> tag. Below is the code responsible fo ...

Limit the rate of GET requests

Currently, I am working with an external API that has a rate limit of 25 requests per second. My goal is to take parts of the results and store them in a MongoDB database. I need help figuring out how to effectively rate limit the request function so that ...