To dynamically set the width of a div based on a calculated percentage from a Webflow CMS collection, you need to use some custom code directly within Webflow. Unfortunately, Webflow does not natively support calculations directly in the designer, but you can achieve this by incorporating JavaScript. Here's how you can approach this:
Example JavaScript:
document.addEventListener('DOMContentLoaded', function() {
document.querySelectorAll('.percentage-div').forEach(function(div) {
var numericValue = parseInt(div.getAttribute('data-value'));
var fixedNumber = 100; // Your fixed number for calculation
var percentageWidth = (numericValue / fixedNumber) * 100;
div.style.width = percentageWidth + '%';
});
});
data-value containing the numerical field value. This can be done using CMS Collections to bind the data attribute with the value.
By using a combination of Webflow’s CMS Collections, custom divs for styling, and JavaScript for calculations, you can dynamically set the width of a div based on a percentage calculated from a CMS item’s numeric field. This approach does not require the use of CSS calc() or jQuery.