Reputation: 21
How do I make a randomly sized image element square and also responsive?
Upvotes: 0
Views: 154
Reputation:
element.style.height = Math.floor(Math.random() * 101) + "%";
element.style.width = Math.floor(Math.random() * 101) + "%";
Math.floor() returns the largest integer less than or equal to a given number
Math.random() returns an number between 0 and 1.
Note that we're using JavaScript because HTML/CSS can't make random number.
From https://css-tricks.com/generate-a-random-number/
Upvotes: 2