Google Answers Logo
View Question
 
Q: XHTML/CSS code needed to get table to behave the way I want ( No Answer,   2 Comments )
Question  
Subject: XHTML/CSS code needed to get table to behave the way I want
Category: Computers > Internet
Asked by: gw-ga
List Price: $10.00
Posted: 13 Jul 2006 12:07 PDT
Expires: 15 Jul 2006 10:29 PDT
Question ID: 746024
First, some context: I am programmatically creating a web page (using
XHTML and CSS) containing a table (a customized TV program schedule)
that is very large (several screens wide and tall).  I'm planning to
use "div" elements rather than table cells for two reasons: 1) to
speed table rendering, and 2) to ensure accurate cell widths so the
program titles won't cause cells to contract and expand.

My question is: Is it possible to obtain the following two behaviors for the table:

1) I would like for the "channel" column to always be visible on the
left edge, regardless of how far the user has scrolled to the right,
but still scroll vertically with the rest of the table.

2) I would like the "time" row to always be visible at the top
regardless of how far the user has scrolled down, but still scroll
horizontally with the rest of the table.

I have tried various combinations of "position:relative" and
"position:absolute" for my "div" elements, but I haven't figured out
how to have a "div" element relative in one direction and absolute in
the other.  Am I overlooking something?

Clarification of Question by gw-ga on 13 Jul 2006 13:14 PDT
To simplify the question,

Is it possible to position a "div" such that its horizontal position
is "fixed" relative to the browser's viewport and simultaneously its
vertical position is "absolute" relative to the rest of the page?

I tried nesting a "fixed" div inside an "absolute" div but "fixed"
divs seem to ignore their containership.

Clarification of Question by gw-ga on 13 Jul 2006 18:28 PDT
I adapted some code that user nschafer uploaded to this web page:

http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21782342.html

The code in question allows modifying an arbitrary property of an
arbitrary class defined in any stylesheet (or inlined in the HTML
page).

The following solution seems to work...

<html>
<head>
</head>
<body>

<style type="text/css">
  .ColHeader {position:absolute; background-color:gold; font-size:24;
top:0px; width:100px; height:50px;}
</style>

<style type="text/css">
  .RowHeader {position:absolute; background-color:gold; font-size:24;
left:0px; width:100px; height:50px;}
</style>

<style type="text/css">
  .TopLeft {position:fixed; background-color:gold; font-size:24;
left:0px; top:0px; width:100px; height:50px;}
</style>

<div style="position:absolute; left:100px; top:50px; height:1500px;
width:1500px; background-color:silver;">GRID CONTENT
PLACE-HOLDER</div>

<div class="ColHeader" style="left:100px;">12:00</div>
<div class="ColHeader" style="left:200px;">1:00</div>
<div class="ColHeader" style="left:300px;">2:00</div>
<div class="ColHeader" style="left:400px;">3:00</div>

<div class="RowHeader" style="top:50px;">Channel 1</div>
<div class="RowHeader" style="top:100px;">Channel 2</div>
<div class="RowHeader" style="top:150px;">Channel 3</div>
<div class="RowHeader" style="top:200px;">Channel 4</div>

<div class="TopLeft" />

<script type="text/javascript"><!--  //
document.onscroll = Snap;
document.onload = Snap();

// set the value of a property of a CSS Rule
function changeClassProperty(sClassName,sProperty,sValue) {
  sClassName="."+sClassName;
  var sheets = document.styleSheets;
  var rules;
  var styleObj;
  for (i=0;i< sheets.length; i++) {
    rules=sheets[i].cssRules || sheets[i].rules;
    for (var j=0; j<rules.length; j++) {
      if (rules[j].selectorText && rules[j].selectorText==sClassName) {
        styleObj=rules[j].style;
        styleObj[sProperty]=sValue;
        break;
      }
    }
  }
}

function Snap(){
   changeClassProperty("ColHeader","top",document.body.scrollTop + "px");
   changeClassProperty("RowHeader","left",document.body.scrollLeft + "px");
}

-->
</script>

</body>
</html>

Clarification of Question by gw-ga on 13 Jul 2006 18:56 PDT
Is there a way to do this with less flicker?  Perhaps using frames?
Answer  
There is no answer at this time.

Comments  
Subject: Re: XHTML/CSS code needed to get table to behave the way I want
From: crythias-ga on 14 Jul 2006 06:15 PDT
 
Something akin to what happens on www.evoketv.com?
Subject: Re: XHTML/CSS code needed to get table to behave the way I want
From: gw-ga on 14 Jul 2006 10:05 PDT
 
crythias-ga:

www.evoketv.com has scrolls nicely verticall but not horizontally.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy