仓库源文站点原文


title: "Debugging CSS" description: "" added: "Oct 10 2021" tags: [css]

updatedDate: "Nov 27 2024"

btn.addEventListener("click", () => {
  const animations = document.querySelector(".circle")
    .getAnimations();

  if (btn.textContent === "Pause Animation") {
    animations.forEach((animation) => {
      animation.pause();
    });
    btn.textContent = "Play Animation";
  } else {
    animations.forEach((animation) => {
      animation.play();
    });
    btn.textContent = "Pause Animation";
  }
});
{
  background-image: url('images/foo.png');
  background-color: #6DB3F2;
}

{
  background: url('images/foo.png'), #6DB3F2;
}

The second one is not shorthand for the first. In the first method, last property (color) takes precedence. The use of the comma in the background property sets multiple backgrounds which get layered on top of each other. The image will be on top, color underneath (opposite of the first method).

MDN docs: You can apply multiple backgrounds to elements. These are layered atop one another with the first background you provide on top and the last background listed in the back. Only the last background can include a background color. You can do this with both the shorthand background property and the individual properties except for background-color.