Is it possible to incorporate multiple gradients into the border-image?

When it comes to the background-image, you have the freedom to include as many radial-gradient and/or linear-gradient as you want. However, for the border-image, it appears that only one gradient can be added. This seems peculiar since the display principle of gradients should theoretically be consistent for both border and background elements, don't you think?

I am curious if there is a method to incorporate more than one gradient in the border-image. I am specifically looking for a solution that relies solely on CSS.

The following code snippet does not work because it entails more than one gradient:

div {
  height: 30px;
  width: 40px; 
  border: 50px solid black;
  border-image: 
  radial-gradient(circle at 20px 30px, green 20px, rgba(0,0,255, .5) 20px),
  radial-gradient(30deg, blue 22px, red 22px);

}

https://jsfiddle.net/thadeuszlay/p6r2p78g/

This example works but consists of only one gradient:

div {
  height: 30px;
  width: 40px;
  border: 50px solid black;
  border-image: radial-gradient(circle at 20px 30px, green 20px, rgba(0, 0, 255, .5) 20px);
}

https://jsfiddle.net/thadeuszlay/p6r2p78g/1/

Answer №1

It is not possible to assign more than one image to the border-image shorthand or the border-image-source longhand property.

According to the specification for border-image-source, only a single image layer can be specified as a value.

Name: border-image-source

Value: none | <image>

In contrast, the background-image property allows for multiple layers to be specified.

Name: background-image

Value: <bg-image> [ , <bg-image> ]*

The specification also introduces the concept of layering for background images, stating that the number of layers is determined by the number of comma-separated values in the ‘background-image’ property.

CSS3 allows for multiple layers in a box's background. The number of layers is determined by the number of comma-separated values in the ‘background-image’ property.

Answer №2

While on my quest for the same solution, I unexpectedly stumbled upon this question.

For those seeking a similar answer, consider this approach:

You can simply incorporate a pseudo-element with its own border as well. To ensure visibility of multiple gradients, it is advisable to utilize transparency.

Here's what I've implemented:

h2{
    --border-width: 8px;

    border-width: var(--border-width);
    border-style: solid;
    border-image: linear-gradient(45deg, #00ff00, transparent 30%);
    border-image-slice: 1;
    font-size: 4rem;
    position: relative;
}
h2::after{
    position: absolute;
    inset: calc(var(--border-width) * -1);
    content: '';
    background: transparent;
    border-width: var(--border-width);
    border-style: solid;
    border-image: linear-gradient(45deg, transparent 70%, #00ff00 100%);
    border-image-slice: 1;
}

I adjusted the inset value in the pseudo-element to align it precisely with the parent's border.

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

Scrolling and adjusting window size while perfectly displaying images pixel by pixel using php and javascript

I'm currently working on a forum concept that will feature images. I'm looking to have the image displayed at default width and height, but also want users to be able to resize the window to view more of the image as needed. Additionally, I would ...

I am looking to place two HTML buttons next to each other on the same line

I am trying to display two HTML buttons next to each other on the same line, with the "Submit Request(s)" button appearing first. The issue I am facing is that the top of the second button aligns with the bottom of the first one. The second button is cor ...

JQuery script fails to load in the head section while dynamically generating an HTML page with JavaScript

Using JavaScript, I have created a new window dynamically and added some HTML code to it. However, when I try to insert a script link into the HTML head, it fails to load when the window is open. <script type="text/javascript"> function newWindo ...

CSS: How come this inline-block div is not appearing on the same line as intended?

I've been tinkering with using display:inline-block on my div elements, and I'm puzzled as to why my two inner divs aren't appearing on the same line. Both divs have a width of 200px, while their parent div is set at 400px. If I switch the ...

What could be causing the absence of the margin in my code?

I am currently working on a website layout where I want to display an image with some information below it, and the information should have a colored background with some margin around it. However, when I try to view the code I have written, the margin i ...

Is there a way to prevent all attribute menu items within a ul/li List from being clicked when one of them has already been selected

When I quickly click on the Photos1, Photos2, Photos3, and Photos4 menus, the "$.get(..." is sent to the server four times. It's important that all of these menus are disabled after any one is clicked. My development environment includes NodeJS, Expre ...

Techniques for parsing a String in Objective-C

I am looking to parse a string to replace certain elements within it. If the string contains an <ol> tag, I want to specifically focus on replacing the <li> elements with numbers. I understand that I can utilize the rangeOfString method to c ...

The speed of the jQuery mouse scroll script remains constant and cannot be altered

I've been searching online... I attempted to adjust the scrolling settings on my website but nothing seems to be working. Does anyone have a guide or list of mouse scroll jQuery scripts and functions? (I've cleared caches, performed cross-brow ...

Troubleshooting directive not functioning properly with AngularJS ng-click

My HTML img tag is not responding to ng-click when clicked. I'm puzzled by this issue occurring in masonryPictureView.html Main page - home.html <ng-masonry> <ng-picture ng-items="projectdescription.pictures"></ng-picture> </n ...

Guide to centering a button on an image using bootstrap 4

I'm having trouble getting three buttons to align vertically in the center of an image using Bootstrap 4. I've tried using position:relative on the image and position:absolute on the buttons, but it's not working as expected. <div class= ...

Best approach for adding an image to an HTML help button: which semantic option is most effective?

Is there a way to create an HTML help button that appears as an image? What would be the most appropriate and semantic approach to achieve this? Below are three different solutions I have considered: 1st idea: Using HTML <button class='help&ap ...

Can you identify the syntax of this LESS variable called @grid-breakpoints with breakpoints for xs at 0, sm at 576px, md at 768px, lg at 992px, and xl at

While exploring the bootstrap less port, I came across this interesting syntax: @grid-breakpoints: xs 0, sm 576px, md 768px, lg 992px, xl 1200px; What exactly is this? It doesn't seem to be a map or an array... How can I retriev ...

Should the username be specified but the password left blank, then an error message will be shown

<div class="form"> <h1>Sign In</h1> <form action="" method="post" name="login"> <input type="text" name="username" placeholder="Enter username" required /> <input type="password" name="password" placeholder="Enter password" ...

Adjust the alignment of text within the <select> tag to the right in Safari browser

Is there a way to align text right in a select option tag? <select style="direction:rtl;text-align:right"> <option value="" selected="">همه</option> <option value="1">راهبر سيستم</option> <option v ...

Concealing a DIV element when the value is not applicable

I'm currently working on a website for a coffee shop product. On this site, each product has a coffee strength indicator that is determined by the database. The strength can be categorized as Strong, Medium, Weak, or n/a (for non-coffee products). If ...

How can I transmit both the $_POST and $_FILE variables to a .php file using Ajax?

I am looking to integrate an ajax image uploading system into my website for various reasons. I want the upload process to be seamless without having to refresh the page. While some jquery plugins have worked well for this purpose, I encountered an issue ...

Verify if there is a date present within the JSON entity

I have a PHP array containing date strings and I want to validate them using a native HTML5 date input element. To achieve this, I have converted the date array into a JSON object for use with JavaScript: <script> var date_array = <?php echo json ...

Steps for adjusting an image in a Bootstrap Carousel

Currently tackling a simple bootstrap Carousel for a school project. I've adjusted the max-height of the images to 400px but it seems like only the top part of the images is visible. I attempted to adjust the margins on the image, and even thought abo ...

Which is more recommended to use in AJAX (XMLHttpRequest) - eventListener or readyStateChange method?

As I revisited a video from WWDC12 discussing advanced effects with HTML5, I couldn't help but notice that for the demo they utilized req.addEventListener("load",callback,true) instead of the usual onreadystatechange. This made me wonder: what differ ...

what strategies can be implemented to prioritize addressing validation errors in return forms

I'm currently working on a web application in asp.net mvc-5, and I have a contact form displayed in the middle of the Contact Us view. Here's the code snippet: <div class="col-sm-8 col-sm-push-4"> <h2>Contact Us1 ...