/*
1. Fallback for the browsers that don't support `fit-content`
*/
P {
max-width: 200px; /*[1]*/
text-align: center; /*[1]*/
max-width: fit-content;
margin: 5rem auto;
}
/*
1. Display file extension, if <a> (achor element) only has href without `data-size` attribute
*/
[href$=pdf]::after {
content: " (PDF)"; /*[1]*/
}
/*
1. Display file extension and file size if <a> (anchor element) has attribute `data-size`.
NOTE: this property will override the property above
*/
[href$=pdf][data-size]::after {
content: " (PDF) (size: " attr(data-size) ")"; /*[1]*/
}
JavaScript
;(function () {
"use strict";
/*
Example of getting data attribute value via JS
*/
const anchorElem = document.getElementById("anchor");
// in Browsers that support dataset
let fileSize = anchorElem.dataset.size;
// in Browsers that don't support dataset
fileSize = anchorElem.getAttribute("data-size");
debugger;
})();
/*
MDN link:
https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes
*/
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.