troubleshooting Question

Css & Jquery: Width, Min Width, Max Width

Avatar of maccaj51
maccaj51Flag for Afghanistan asked on
CSSHTMLjQuery
3 Comments1 Solution1090 ViewsLast Modified:
Hi Experts,

I am pretty sure I know the answer to this already, but thought I'd get a set of extra eyes on it.

I have the code below and I'm trying to get the grids to fill the container within the css width parameters that I have set.

At the moment it happens like this:
1) When the container becomes to small it kicks a grid to the next row
2) The grids then get smaller to try and stay on the rows they are currently on
3) They then stay at min width until they all cascading down one by one.

Ideally I would like them to fill the container across as much as possible until one jumps to next row... but then they all go back to max width and process happens again.

Now I am sure this will have to be a jquery window load and resize function... but was wondering whether anyone could point out an easier way or help down the path to creating this function as best possible

Many Thanks in advance

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Grid</title>
<style type="text/css">
body {
	margin: 0px;
}
#container {
	width: 100%;
	background-color: #033;
	overflow: auto;
}
#container .grid {
	display: inline;
	float: left;
	height: 240px;
	background-color: #0F6;
	min-width: 240px;
	max-width: 320px;
	width: 25%;  /* Starting at 25% as this would create 4 across on popular screen resolutions */
}
#container #grid1 {
	background-color: #c42;
}
#container #grid2 {
	background-color: #3C6;
}
#container #grid3 {
	background-color: #CC6;
}
#container #grid4 {
	background-color: #993;
}
#container #grid5 {
	background-color: #633;
}
#container #grid6 {
	background-color: #C96;
}
</style>
</head>
<body>
<div id="container">
  <div class="grid" id="grid1"> </div>
  <div class="grid" id="grid2"> </div>
  <div class="grid" id="grid3"> </div>
  <div class="grid" id="grid4"> </div>
  <div class="grid" id="grid5"> </div>
  <div class="grid" id="grid6"> </div>
</div>
</body>
</html>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros