This is an example of what you should be able to do once the major browsers implement some seriously cool features in the CSS3 draft spec as of April, 2016:
--name: value
assignment and var(--name)
accessor syntax. (Already implemented by Chrome, Firefox, and Webkit!)px
or em
from a percentage. (Partially implemented in Chrome, Firefox, and Safari.)attr(attr-name units)
. (Not yet implemented in any major browser.)Together, these features would enable us to use HTML element attribute values as the basis for calculated values in CSS on a per-element basis, and define (then change) which property the values are applied to. This would open up possibilities for more data-driven design entirely in CSS, without the need for JavaScript.
Note: I've used the x-
prefix to denote HTML custom elements, which are a great way to simplify your markup, encapsulate your CSS, and extend the DOM element API via JavaScript. You could just as easily HTML5 elements or classes, though.
xxxxxxxxxx
<html lang="en">
<head>
<link rel="stylesheet" href="bar-chart.css">
</head>
<body>
<x-bar-chart min="0" max="200">
<x-bar value="200">A: $100</x-bar>
<x-bar value="150">B: $150</x-bar>
<x-bar value="25">C: $25</x-bar>
</x-bar-chart>
</body>
</html>