Can the size of a linear gradient be predetermined in CSS?

When working with CSS, it's possible to set various properties of a linear gradient such as color, position, orientation, and width. However, is it feasible to define its length? I prefer not to use SVG and am specifically looking for a CSS-based solution.

My goal is to create something akin to an eye iris using a linear gradient: https://i.sstatic.net/g5RyK.jpg

The issue with linear gradients is that they tend to create an infinite stripe. Is there a way to restrict this stripe within a certain range?

So far, I've managed to adjust the color, width, position, and orientation of the gradient, but I haven't been successful in controlling its length:

div {
  height: 100px;
  width: 100px;
  background: white;
  background-image: 
  linear-gradient(45deg, transparent 70px, red 70px, black 72px, transparent 72px),
  linear-gradient(-45deg, transparent 70px, red 70px, blue 72px, transparent 72px),
  radial-gradient(circle at 50px 50px, green 5px, transparent 40px);
}

https://jsfiddle.net/thadeuszlay/vy9o81dy/

Answer №1

If you want to customize the colors in a radial gradient, you can do so easily. Check out this example:https://jsfiddle.net/vy9o81dy/2/

radial-gradient(circle at 50px 50px, transparent 5px,  green 5px,transparent 40px);

<edit for feedback/> Is this what you were trying to achieve as well? Take a look: https://jsfiddle.net/vy9o81dy/3/

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

How to use javascript/html to differentiate between male and female names?

I've developed a random name generator code that is powered by both CSS and JavaScript. Currently, the code allows me to input any name - regardless of gender - press the generate button, and receive a randomly generated first and last name. However, ...

What methods does a browser use to identify SCSS files?

While exploring this html template in Chrome's inspection tool, I was amazed to see that the browser was able to detect the scss files instead of the compiled css version. To investigate further, I pressed Ctrl+U to view the page source, hoping to fin ...

Creating a button in HTML that deletes code from a program: a step-by-step guide

Let me illustrate what I'm endeavoring to achieve. Below is the actual code: var info = { labels: ["March", "April"], datasets: [ { label: "Primary Info", fillColor: "rgba(220,220,220,0.2)", strokeColor: "rgba(220,220,220 ...

Why isn't my easypie number displaying on the inside?

I am currently utilizing the easypie plugin, but I am facing an issue where the number is not displaying inside the pie chart. Despite trying multiple solutions, I haven't been able to resolve this. How can I successfully display the number inside the ...

Change the color of the text in a shiny dashboard

While exploring shiny dashboard, I came across this link that explains how to modify colors in the sidebar and header. However, I'm struggling to change the font color for sidebar items. The default white font color becomes unreadable when using light ...

Customizing the attribute of an HTML tag using EJS or jQuery

Within my express server, I am rendering a page with the following data: app.get('/people/:personID', function (req, res) { res.render("people/profile", {person: req.person }); }); Inside my profile.ejs file, I can display the data within an ...

Instructions for extracting the href value from an anchor tag using JavaScript within a specified string

How can I retrieve the href value of the last anchor tag in the provided content string using pure JavaScript, excluding jQuery? var contents = '<div id="content"><a href="http://www.okhype.com/wp-content/uploads/2016/12/ruffcoin-made-in-aba ...

Replace all existing content on the webpage with an exciting Unity game upon clicking

In an interesting experiment, I am trying to hide a secret href that, once clicked, has the power to wipe out everything on the page, leaving it temporarily blank before replacing it with a captivating Unity game that takes over the entire page. Let me sh ...

The window.load() function seems to be malfunctioning as the event is not being triggered. There are no error

I'm struggling with getting the window.load() event to trigger on this specific website. The issue arose last night and despite there being no visible js or php errors, pinpointing the root cause has proven to be quite challenging. In syrp.home.main ...

How to perfectly position multiple tables using CSS

I am relatively new to the world of HTML and CSS. I have successfully created several tables, but now I am struggling to display them all on a single line within a designated box. Despite my best efforts, I have not been able to achieve the desired result. ...

I want to learn how to change the background image in React based on different components

Hey there! I've been learning and came across the Tomorrowland website. I really love the background scrolling effect on the homepage, where it changes depending on the component. I'm not sure how to code it myself and could really use some assis ...

`Using a Video in a JQuery Carousel`

Currently in the early stages of developing a JQuery Slider that will kick off with a video, transitioning into slideshow mode once the video concludes. My goal is to ensure compatibility with IE9 and lower, as well as iPhone devices, necessitating options ...

Issue with Angular select box not showing values when binding Ngmodel

I recently started working with Angular and encountered an issue while trying to display objects in a select box through looping. Instead of showing the values, I only see a blank dropdown. Here is a snippet from my HTML page: <div *ngIf="userPerm ...

What steps should I follow to track an event using Firebug?

When I examine the element, how can I discover all of the events that are attached to it? ...

Stopping the sound when its' Div is hovered over

I've managed to successfully trigger the audio to play on hover, but I'm having trouble getting it to pause when my mouse leaves the area. Check out the code in action here: https://jsfiddle.net/jzhang172/nLm9bxnw/1/ $(document).ready(functio ...

Implementing universal styles to injected HTML (v-html)

I am facing an issue while injecting HTML content from my database using Vue. The problem is that although I can successfully inject the HTML, the framework stylesheet (Vuetify) does not seem to be applied to the injected content. The rest of the page ha ...

Selecting Radio Buttons using Selenium with Java

Having trouble locating the XPath for checking radio button selection in Selenium with Java. I am attempting to determine if the "one way" checkbox is selected, and if so, select the two way checkbox. However, each time I run the code, it only recognizes t ...

What is the process for setting up both an open and closed status for my accordion?

After browsing through multiple threads on accordions, none seem to match my current structure which I believed was effective. In an attempt to learn and build elements from scratch, I created the following accordion with some help from Google and experi ...

Why is SVG not adjusting to the screen size properly?

How can I make an SVG fit to its parent <div>-container and resize with the screen size? My initial plan involved controlling the size of the SVG based on the percental width and height of the parent <div>-container. Looking for any suggestio ...

What is the best way to incorporate modal window parameters into this code snippet?

JavaScript function: function loadBlockEditor(block, username) { var blockInfo = $.ajax({ url: "in/GameElement/BlockEditor.php", type: "GET", data: 'block=' + block + '&nick=' + username, dataType: "html" }); b ...