Use CSS to reorder DIVS?

I have a set of divs.  What I want is to be able to reorder them dynamically.  For instance, one client may want to display 1, 2, 3, 4 (vertical) and another might want to show the page with modulels in different order, like 3, 2, 4, 1.  Each client could have a different layout.  

They will also be able to select different font styles and sizes, so the divs won't have the same size for each client.  I'm cosing for IE (using ASP).  Is there some way to do this without a lot of code-behind or similar?  Ideally it would be purely CSS.
jdhibberdAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VirusMinusCommented:
CSS is client side. not server side.

Is the user going to choose what order they would like the divs in? or is it random?

The way i can think of doing this is to use dynamic CSS, i.e the CSS is written out using server side code.

eg.

your CSS file can be a server side code file, like styles.asp and in there you can conditionally exclude or write out CSS

eg.

<link rel="stylesheet" type="text/css" title="alt" media="screen" href="style.asp?order=1" />

you could write out the link rel with a random number or a number option chosen by the user.

eg.

<link rel="stylesheet" type="text/css" title="alt" media="screen" href="style.asp?order=<%=anyRandomNumber%>" />

in the file you can then use server side loops, conditional statements, switch case etc. and output your CSS. but for this to work, you must set the MIME content type of the file to "text/css", this can be done in asp as
<% Response.ContentType = "text/css" %>

ideally put the MIME content type statement as the first line. then in your style.asp you could do something like this;

so your styles.asp CSS file could look something like this;

'styles.asp
'-----------
<% Response.ContentType = "text/css" %>
body {
<%
if request("color") = "" then
%>
color: red;
<%
else
%>
color: <%=request("color")%>;
<%
end if

'check querystring value
if request.querystring("order") = 1 then

'put one order of divs here

elseif request.querystring("order") = 2 then

'put different order of divs here

else

'put another order here

end if
%>
}
'------------------
0
Steve BinkCommented:
Another idea, based in javascript.  This means you should not have to reload the page to reorder the divs, but this is not a purely CSS solution.

Create a javascript array of the heights of each of the 4 divs.  When a reorder is completed you should have an array of the new order.  For each div in the neworder, set its top property to be (top of first div + height of every div before it).  For example, when the page starts, maybe it is array(1,2,3,4).  After reorder will look like:

var baseheight=100;  // the absolute top of the very first div
var heights=(220,180,60,40);
var neworder = (2,1,4,3);  // set by the user through your interface
for (w=0;w<neworder.length;w++) {
  thisdiv = neworder[w] - 1; // index starts at 0
  newheight = 0;
  for(z=0;z<w;z++) {
    newheight += heights[neworder[z]];  //get the height for the div pointed to by neworder[z]
  }
  // now newheight hold the combined height of previous divs
  // add the baseheight to get the new top value
  newtop = baseheight + newheight;
  // set the properties on div[w] now
  document.getElementById('div' + w).style.top=newtop;
}

This is rough, and will need love to work properly, but should give you the general idea.  The arrays for original heights can be constructed after the page has been loaded, or maybe even database driven.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jdhibberdAuthor Commented:
It took a bit of massaging, but the javascript is working like a charm.  Thanks for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.