I need to set specific minimum and maximum values for the width and height of left-floated divs and make them expand to fill the parent element (body). I am curious if there is a way to achieve this using CSS, or if I should resort to JavaScript.
When you resize the window, you will see empty space on the right of the divs until there is enough space for more divs to fit in. My goal is to have all the divs expand to occupy the empty space until they reach the maximum size, at which point additional divs will adjust based on the number in each row.
In essence, I want these divs to always stay within the specified minimum and maximum widths and heights while flexibly adjusting to fill the entire width of the body.
Here's the sample code:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<style>
.imageitem {
background-color: blue;
margin: 0 5px 5px;
min-width: 200px;
min-height: 200px;
max-width: 250px;
max-height: 250px;
float: left;
}
</style>
</head>
<body>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
<div class="imageitem"></div>
</body>
</html>