I am attempting to add a linear gradient border around a dynamically created div using JavaScript. However, I am not seeing the border show up as expected and it is not displaying in black.
Check out my code snippet below:
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>
I am running Firefdox version 126.0.1 (64-bit), which should support the use of gradient
with the border-image
property from v29 onwards.