473,379 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Cross browser horizontal overflow

I have a table that sizes to take up most of the page's width. The
(mostly empty) rightmost cell of a particular row starts off as wide as
it can, but it might be that it gets something that exceeds its initial
width, such as a long web address. In this case, I would like the
horizontal overflow to be active. However, it seems that if I affix
the style overflow-x:auto, then IE6 will cover the bottom line (of the
text) with the horizontal scroll bar upon overflow and FF 1.5 will do
the same if there is only one line involved (thus showing nothing).
Having the scrollbar cover text is not my idea of good horizontal
scrolling.

So the following accomodates various line counts in IE6 and FF 1.5. If
there are comments towards simplification/improvement, please share.

Csaba Gabor from Vienna
<html><head><title>Overflow demo page</title></head>
<body bgcolor=yellow style=margin-left:.4in>
<table id=mytab width="100%" border>
<tr><td width='1%' valign=top><nobr>Row 1</nobr></td>
<td valign=top><div id=mydiv style="overflow-x:auto">
Longer text goes here</mydiv></td></tr>
<tr><td colspan=2>Second line</td></tr>
</table>
<br><br>
<table border id=tblBtns>
<tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>

<tr><td colspan=2 align=center><button
onclick="return changeDiv('broken')"
type=button>Style: broken</button></td></tr>
<script type='text/javascript'>
// install the buttons
var tblBtns = document.getElementById('tblBtns');
for (var i=1;i<=3;++i)
for (var j in {short:0, long:1}) {
var html = "<button type=button " +
"onclick=\"return changeDiv('" +
j + "', " + i + ")\">Lines: " +
i + ", style: " + j + "</button>";
tblBtns.rows[i-1].cells[j=="long" ? 1 : 0]
.innerHTML = html; }

// fix the special div's width to engage overflow handling
var mydiv = document.getElementById('mydiv');
mydiv.setWidth = mydiv.style.width = mydiv.offsetWidth;

function repeat(str, amount, sep) {
// repeat string (str) amount times, separated by sep
if (!sep) sep = "";
for (var final=""; amount; amount>>=1,str+=sep+str)
if (amount&1) final += (!final?"":sep) + str;
return final; }

function changeDiv (style, lineCount) {
// change the text of the top row, right cell
var div=document.getElementById('mydiv');
var aText = ["This", "text", "is", "repeated", 7, "times"];
var separator = (style!="long") ? " " : "_";
var count = (style=="long") ? 10 : 1;
if (style=="broken") lineCount = 25;
aText[4] = count * lineCount;
var baseText = aText.join(separator);
var lineUnit = repeat(baseText, count);
var lineSep = (style=="broken") ? "" : "<br>";
div.innerHTML = repeat(lineUnit, lineCount, lineSep);
if (div.scrollWidth>div.setWidth &&
div.scrollHeight==div.offsetHeight)
div.innerHTML += "<br>&nbsp;";
return false; }
</script>
</body></html>

Nov 5 '06 #1
2 5221
VK
<http://groups.google.com/group/comp.lang.javascript/msg/b2f517d04b0749f5>
If there are comments towards simplification/improvement, please share.
It is a nice code working as intended. I just don't like
"non-structural structures" :-) in documents: thus elements that are
not implied by the document content but used as presentational
workarounds. In this case that would be great to avoid somehow DIV
wrapper in the TD. I realise that it's hardly/not doable. So please
take it as a general wishful comment.

Nov 5 '06 #2
Csaba Gabor wrote:

[snip]
<html><head><title>Overflow demo page</title></head>
<body bgcolor=yellow style=margin-left:.4in>
<table id=mytab width="100%" border>
<tr><td width='1%' valign=top><nobr>Row 1</nobr></td>
<td valign=top><div id=mydiv style="overflow-x:auto">
Longer text goes here</mydiv></td></tr>
<tr><td colspan=2>Second line</td></tr>
</table>
<br><br>
<table border id=tblBtns>
<tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>

<tr><td colspan=2 align=center><button
onclick="return changeDiv('broken')"
type=button>Style: broken</button></td></tr>
<script type='text/javascript'>
// install the buttons
var tblBtns = document.getElementById('tblBtns');
for (var i=1;i<=3;++i)
for (var j in {short:0, long:1}) {
var html = "<button type=button " +
"onclick=\"return changeDiv('" +
j + "', " + i + ")\">Lines: " +
i + ", style: " + j + "</button>";
tblBtns.rows[i-1].cells[j=="long" ? 1 : 0]
.innerHTML = html; }

// fix the special div's width to engage overflow handling
var mydiv = document.getElementById('mydiv');
mydiv.setWidth = mydiv.style.width = mydiv.offsetWidth;

function repeat(str, amount, sep) {
// repeat string (str) amount times, separated by sep
if (!sep) sep = "";
for (var final=""; amount; amount>>=1,str+=sep+str)
if (amount&1) final += (!final?"":sep) + str;
return final; }

function changeDiv (style, lineCount) {
// change the text of the top row, right cell
var div=document.getElementById('mydiv');
var aText = ["This", "text", "is", "repeated", 7, "times"];
var separator = (style!="long") ? " " : "_";
var count = (style=="long") ? 10 : 1;
if (style=="broken") lineCount = 25;
aText[4] = count * lineCount;
var baseText = aText.join(separator);
var lineUnit = repeat(baseText, count);
var lineSep = (style=="broken") ? "" : "<br>";
div.innerHTML = repeat(lineUnit, lineCount, lineSep);
if (div.scrollWidth>div.setWidth &&
div.scrollHeight==div.offsetHeight)
div.innerHTML += "<br>&nbsp;";
return false; }
</script>
</body></html>
This isn't very important, but my Mozilla is not vary happy with it :-)
You're using three reserved keywords as variable names
here:
for (var j in {short:0, long:1}) //line 24 in my cut'n'paste

and here:
for (var final=""; amount; amount>>=1,str+=sep+str) //line 39

--
Riccardo
Nov 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: Marian Aldenhövel | last post by:
Hi, I am in the process of embarking on building a large web application. I wanted to seize that opportunity to learn how to use CSS and get rid of my ad-hoc approach to HTML-coding (i.e.: add...
1
by: Peter Mount | last post by:
Hi When I zoom into my site (http://www.petermount.au.com) with Opera 7.54 the horizontal scrollbar doesn't show when the site image is bigger than my screen. Yet the horizontal scrollbar shows...
5
by: Jsp | last post by:
I created a vertically scrolling div. On initial rendering, Firefox shows a horizontal scrollbar in this div, over the complete width. Resizing the width of the window/viewport makes the horizontal...
12
by: Kepler | last post by:
How do you get the height of the client browser in IE? Both document.body.clientHeight and document.body.offsetHeight return the height of the document. If the page is long and there's a vertical...
0
by: Lucas, Todd | last post by:
Hello everyone! I'm having a problem with a WebControl that I'm designing for a Menu. I've been at it for about 3 weeks now, and can't seem to get around this problem. So I'm hoping that someone...
2
by: musicmouse | last post by:
Happy new year to you all, I have a problem with the css settings for the horizontal scrollbar of a textarea. When I look at my textarea's in Internet Explorer (I use 5.5) I see only a...
1
by: Dan | last post by:
Hi, I was wondering if anyone could come up with a cross browser image transition that I could use... I have already made one that works in IE but i know it doesn't work in Mozilla Firefox. ...
2
by: sachjn | last post by:
Hi, I need to have a table along with other UI items in page which resizes horizontally and vertically with the browser window. That means table should accoupy the remaining available space in...
1
by: newbie009 | last post by:
How can I disable horizontal scroll in textbox for FireFox? Right now 1 textbox has vertical scroll and other textbox has horizontal scroll. It only looks like this on FireFox but it looks ugly....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.