473,782 Members | 2,485 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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><ti tle>Overflow demo page</title></head>
<body bgcolor=yellow style=margin-left:.4in>
<table id=mytab width="100%" border>
<tr><td width='1%' valign=top><nob r>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>Secon d 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><b utton
onclick="return changeDiv('brok en')"
type=button>Sty le: broken</button></td></tr>
<script type='text/javascript'>
// install the buttons
var tblBtns = document.getEle mentById('tblBt ns');
for (var i=1;i<=3;++i)
for (var j in {short:0, long:1}) {
var html = "<button type=button " +
"onclick=\"retu rn 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.getEle mentById('mydiv ');
mydiv.setWidth = mydiv.style.wid th = mydiv.offsetWid th;

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.ge tElementById('m ydiv');
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(sepa rator);
var lineUnit = repeat(baseText , count);
var lineSep = (style=="broken ") ? "" : "<br>";
div.innerHTML = repeat(lineUnit , lineCount, lineSep);
if (div.scrollWidt h>div.setWidth &&
div.scrollHeigh t==div.offsetHe ight)
div.innerHTML += "<br>&nbsp; ";
return false; }
</script>
</body></html>

Nov 5 '06 #1
2 5250
VK
<http://groups.google.c om/group/comp.lang.javas cript/msg/b2f517d04b0749f 5>
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><ti tle>Overflow demo page</title></head>
<body bgcolor=yellow style=margin-left:.4in>
<table id=mytab width="100%" border>
<tr><td width='1%' valign=top><nob r>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>Secon d 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><b utton
onclick="return changeDiv('brok en')"
type=button>Sty le: broken</button></td></tr>
<script type='text/javascript'>
// install the buttons
var tblBtns = document.getEle mentById('tblBt ns');
for (var i=1;i<=3;++i)
for (var j in {short:0, long:1}) {
var html = "<button type=button " +
"onclick=\"retu rn 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.getEle mentById('mydiv ');
mydiv.setWidth = mydiv.style.wid th = mydiv.offsetWid th;

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.ge tElementById('m ydiv');
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(sepa rator);
var lineUnit = repeat(baseText , count);
var lineSep = (style=="broken ") ? "" : "<br>";
div.innerHTML = repeat(lineUnit , lineCount, lineSep);
if (div.scrollWidt h>div.setWidth &&
div.scrollHeigh t==div.offsetHe ight)
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
2677
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 tables until either the result is OK or I decide to start over). However I do not seem to be able to get it right. Experimentation is beginning to wear me out...
1
3221
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 in print preview and when I turn css off in Opera. Could it be a problem with my css? The code is: html{ padding-top: 0; padding-bottom: 0;
5
11197
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 scrollbar disappear and never come back again, because the content is "liquid". Resizing the window/viewport vertically, makes the scrollbar come back again. IE and Opera don't show this behaviour. Page: http://www/lahaina.nl/index.htm CSS:...
12
10176
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 scrollbar, you get the height of the entire document, screwing up any chance of centering a window in the browser using these values. Is there a way to get the height of the actual browser window and not the entire page height? Thanks.
0
1598
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 can help me ... My environment: VS 2003 v7.1.3088, Win2K v5.0.2195 SP3, IE6 v6.0.2800.1106 browser. I have a class (C3Menu) derived from WebControl, with a property (MenuItems) that is a collection of menu items. The collection property is...
2
104913
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 vertical scrollbar when the area contains a too long text. IE wil just break off the text at the limit if a single word is too long and put the next character on the next line. For me this is the desired bahaviour (those horizontal scrollbars take too...
1
3154
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. Below is the script I have made, there is only one error with it (besides compatabilty), the fact that you can make the images transition even when there is already a transition occuring, I have tried to compensate for this, but it doesn't work......
2
4708
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 the browser window and should display horizontal and vertical scroll bars if content of table is more than available width & height. I can do similer to this by enclosing table in a <DIV> with style as : overflow:auto; height:200px etc. But things...
1
4362
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. http://jumbofiles.com/example.gif I used this code but it only worked for IE not FireFox: style="overflow: scroll; overflow-y: scroll; overflow-x: hidden; overflow:-moz-scrollbars-vertical;" Basically I want only vertical scroll.
0
9641
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10080
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2875
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.