Skip to content

HTML5 Data Attributes and :before / :after content images, any support? #758

@FingerFeat

Description

@FingerFeat

Heya!

I was currently trying out throwing a URL to an image into a HTML5 data attribute in order to fetch it through CSS/LESS afterwards, injecting it as a content: url() in a pseudo-element (:before & :after), but it seems that despite any kind of black magic tricks I pull off, it will only spit out "attr(data-src)" as a string. Here's an example:

In the HTML:

In the LESS/CSS file:

[data-src] { width: 100%; height: 350px; }

[data-src]:before {
@imageurl: attr(data-src);
content: url(@imageurl);
width: 100%;
height: 100%;
}

The output in the content is "attr(data-src)" (which yes, it makes sense, I know, but you hopefully get my point) and not "image.png".

Is there any chance of getting LESS to take the content of the data attribute and not literally turn "attr(data-src)" into a string? I'm crossing my fingers here as it can be used for some very interesting things.

Big thanks for making LESS! It's amazing.

  • Anders

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions