Skip to content

Proposal for ::drag-image to style the after-image of dragged elements #13198

@sunkanmii

Description

@sunkanmii

Following the proposal set in #11584, I suggest we also have a pseudo-selector called ::drag-image.

An example of what I mean is the little style you see in this demo when the nav element is dragged:

https://codepen.io/sunkanmii-the-styleful/pen/xbZLJvY

Hear me out, please. Instead of having JavaScript insert the styling for us or use CSS hacks, why can't we just have a pseudo-selector dedicated to just styling that dragged after-image?
i.e Instead of doing this with JS and the HTML Drag and Drop API:

menuBar.addEventListener("dragstart", (event) => {
  const dragPreview = document.createElement("div");
  dragPreview.textContent = "📦 Dragging...";
  dragPreview.style.cssText = `
    padding: 0.5rem 1rem;
    background: #fff6d6;
    color: #333;
    border: 2px dashed orange;
    border-radius: 0.5rem;
  `;

  document.body.appendChild(dragPreview);
...

I can simply just write this in CSS to style that after image:

::drag-image{
    content: ;
    padding: 0.5rem 1rem;
    background: #fff6d6;
    color: #333;
    border: 2px dashed orange;
    border-radius: 0.5rem;
}

I'm open to suggestions on this, please. P.S it's my first issue on W3C, yay! (I think).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Agenda+ LaterLower-priority items that are flagged for CSSWG discussioncss-ui-5

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions