I’m trying to make a linear gradient border around a div I’m creating dynamically with JS. Unfortunately, no border shows up, as far as I can tell (and no, the border’s not (or shouldn’t be) showing up black.
Here’s my code:
const devlogList = document.createElement("ul");
devlogList.classList.add("cards");
const devlogs = [{
name: "Upriver (placeholder)",
gradientTopLeft: "red",
gradientTopRight: "blue",
imageSrc: "exampleimage.png",
description: "description",
status: "status",
}];
for (let i = 0; i < devlogs.length; i++) {
const devlogItem = document.createElement("li");
const devlogDiv = document.createElement("div");
devlogDiv.classList.add("devlog");
const devlogTitle = document.createElement("p");
devlogTitle.style.color = devlogs[i].gradientTopLeft;
devlogTitle.innerText = devlogs[i].name;
const devlogStatus = document.createElement("p");
devlogStatus.innerText = devlogs[i].status;
devlogDiv.appendChild(devlogTitle);
devlogDiv.appendChild(devlogStatus);
devlogItem.appendChild(devlogDiv);
devlogList.appendChild(devlogItem);
}
document.getElementById("devlogs").appendChild(devlogList);
.devlog {
list-style-type: none;
border-image: linear-gradient(to bottom right, blue, red) 1;
width: 500px;
}
body {
background-color: black;
color: white;
}
<div id="devlogs"></div>
Also, I’m using Firefox v126.0.1 (64-bit), which is supposed to support the use of gradient
with the border-image
property as of v29.
2
Answers
Just set border-style in your .css
Per MDM "some browsers don’t render the border image if border-style is none or border-width is 0."