user6711198
user6711198

Reputation: 21

How do I make a randomly sized image element square and also responsive(% width and not pixels)?

How do I make a randomly sized image element square and also responsive?

Upvotes: 0

Views: 154

Answers (1)

user6599592
user6599592

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

Related Questions