Is there a way to produce random colors using this SCSS function?

The current function is returning an output in the color #ff0063, but my goal is to create a variety of colorful pixel dots on the screen. Could someone provide an explanation of what this code is doing?

@function multiple-box-shadow ($n) {
  $value: '#{random(2500)}px #{random(2500)}px #ff006e';
  @for $i from 2 through $n {
    $value: '#{$value} , #{random(2500)}px #{random(2500)}px #ff006e';
  }
  @return unquote($value);
}

Answer №1

The SASS function random() generates a random number up to the value you provide. This means that the code snippet is producing multiple box-shadow values with random positions within a range of 2500px from the original element.

If you want to include random colors as well, you can use three random(255) arguments inside the rgb() function, like this:

@function multiple-box-shadow ($n) {
  $value: '#{random(250)}px #{random(250)}px #ff006e';
  @for $i from 2 through $n {
    $value: '#{$value} , #{random(250)}px #{random(250)}px rgb(#{random(255)}, #{random(255)}, #{random(255)})';
  }
  @return unquote($value);
}

See it in action here

Please note that in the demo, the random positioning is limited to 250px to ensure everything fits nicely on the screen.

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

the content outside of the division is incorrectly formatted

Here is the code snippet that I am working with: <html lang='es'> <head> <link rel="stylesheet" type="text/css" href="theme.css"> <link rel="stylesheet" type="text/css" href="bootstrap337/css/bootstrap.mi ...

Issues with AngularJS UI Router functionality are being experienced specifically on localhost

What is causing the discrepancy in UI-Router functionality between JSFiddle and localhost? The localhost link is http://127.0.0.1:54046/preview/app/index.html. Have I overlooked something crucial here? There are no visible JS errors present in the console. ...

Disabling modal popup buttons in Bootstrap 4 using Javascript

JSFiddle DEMO: https://jsfiddle.net/2yx16k8L/ I'm encountering an issue with my JS code. I want a click on a div to open the entire content within it. However, this action is causing the modal button in the dropdown to stop working. How can I resolve ...

What could be the reason for the lower section of my website not being displayed?

I'm having an issue with a new div I added to the bottom half of my website - it's not showing up. Oddly enough, when I test the same code on a separate web page, it works fine. Can someone please take a look at the code and help me out? Thank yo ...

Is there a simple and efficient method to transition the loading of a regular website to AJAX for the entire site?

Is it feasible to easily and quickly change all links on a website to load the URL that the user clicked via AJAX, rather than refreshing the webpage? My website currently has standard links, but in order to create a mobile application for iPhone, I need ...

Can the text inside a div be styled to resemble h1 without using an actual h1 tag?

Is it feasible to apply the h1 style to all text within a div without utilizing tags? For instance: <div id="title-div" style="h1">My Title</div> Or a potential solution could be: #title-div { style: h1; //Imports all s ...

What is the best approach to linking my divs using unique ids in jquery?

When working with this HTML structure: <a href="#" id="link-23">User 23</a> <a href="#" id="link-24">User 24</a> <div id="user-23">Bob</div> <div id="user-24">Tim</div> I am currently exploring how to crea ...

Is there an alternative function that can be used in place of live() in jQuery version 1.26?

$('#data').find('div:eq(0)').append('<span class="show"> | show more</span><span class="hide"> | hide content</span>') $('div:gt(0)').hide(); $('.show, .hide').on('click', ...

Using Html.BeginForm to route to a Web Api endpoint

I need help figuring out how to make my page post to my Web API controller instead of my Area/Controller/Action. I've tried using both Html.BeginForm and Ajax.BeginForm, but haven't had any success so far. Here's what I've attempted: @ ...

Unlimited scrolling feature on a pre-filled div container

Looking for a way to implement infinite scroll on a div with a large amount of data but struggling to find the right solution? I've tried various jQuery scripts like JScroll, MetaFizzy Infinite Scroll, and more that I found through Google search. Whi ...

How can I display multiple images in a single row using PHP echo?

I am struggling with my PHP code that displays images from a database. The issue I'm facing is that the images are all appearing in a single column, but I want them to be displayed in one row so that users can scroll horizontally to view them. How can ...

What is the best way to implement data loading on scroll in HTML with AngularJS?

I'm working with a HTML Dynamic Table <div class="clearfix reportWrapper" > <div class="reportTable"> <table class="table table-bordered footerBGColor"> <thead fix-head class="headerTable"> ...

Error message displayed: "Validator.elementValue is not a recognized function in JQuery Validation."

I am facing an issue with my form where I have two fields and I need at least one of them to be filled. I tried using a JQuery validate plugin but it seems that the require_from_group function is not working properly. Upon inspecting the console, I encoun ...

Guide to displaying a function result in Vue 3

I have just started learning vue js and I am facing an issue. I want to display the value returned by the following function in a table row: The function is: getGroup(id){ this.users.forEach(element =>{ if(element.id===id) ...

I am having issues with my search form - it doesn't appear to be

I am trying to create a search form that will display users (username, firstname, or lastname) from my database as the user types, similar to how Facebook and Twitter do it. However, when I click on the search button, nothing happens. Below are two parts o ...

Running a setTimeout function within the context of a jQuery each

My goal is to animate characters one by one, but for some reason the following code isn't functioning as expected: $('.overlay-listing').hover(function(){ var idx = 1; $('.strip-hov span', this).each(function(){ if ...

Issue encountered with AJAX multiple image uploader

I'm attempting to create an PHP and JavaScript (jQuery using $.ajax) image uploader. HTML: <form method="post" action="php/inc.upload.php" id="upload-form" enctype="multipart/form-data"> <input type="file" id="file-input" name="file[]" a ...

What is causing the Invalid left-hand side error in the postfix expression at this specific line of code?

I encountered an error stating "invalid left-hand side in postfix expression" while trying to execute this particular line of code data: 'Action=AutionMaxBid&AuctionItemID='+<?php echo $bidItemID ;?>+'', This error occurred d ...

Can an advertisement's appearance be altered to include custom content using only CSS?

Dealing with SAP for our ticket system has been quite a challenge due to the design that is causing some frustration. In an attempt to make it more tolerable, I used CSS to make some adjustments. However, my problem now lies in the fact that they keep maki ...

Guide on creating uniform heights and widths for images with varying dimensions utilizing CSS (and percentage values)

Is there a way to ensure that all images maintain the same height and width using CSS percentages, rather than set pixel values? I'm working on displaying images in circles, where most are uniform in size but a few outliers distort the shape. The wide ...