Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

HTML Forum


You are currently viewing our HTML Forum as a guest. Please register to participate.
Login



Post a Project »

Find a Professional HTML Freelancer!

Find a Freelancer to help you with your HTML projects

FREE Outsourcing eBook!

Reply
Old 08-09-2007, 01:02 PM DIVs RESIZE TD
Novice Talker

Posts: 5
Trades: 0
Hello there.. This time Google didn't help me much on this:

There are several divs in a td, but only one of them is displayed at a time (display:inline), the other having display:none for style. It would be nice if the td (table) didn't resize when switching between divs, but keep the size of the first displayed div. Then, if a div was bigger it would become scrollable.

I tried lots of combinations of height, min-height, max-height, clientHeight, overflow, table-layout:fixed, size capture on body load etc., but it didn't work out as planned..

Here is an experiment:

Code:
 <table>
<tr>
<td>
<div id="div1" style="width:100;height:100;overflow:auto;display:none">
1<br>
2<br>
</div>
<div id="div2" style="width:100;height:100;overflow:auto">
% for my $i (1..20) {
<% $i %><br>
% }
</div>
</td>
</tr>
<table>

<script type="text/javascript">
function s() {
document.getElementById("div1").style.display = "inline";
document.getElementById("div2").style.display = "none";
}
</script>

<input type="button" value="Switch" onclick="return s()" />
There are 2 divs: div1 and div2 by their IDs. Each is set "width:100;height:100;overflow", but only div2 is displayed. div2 contains the numbers from 1 to 20 each on a separate line, while div1 contains 1<BR>2. When the page loads div2 is indeed 100 x 100 with scroll bars to accommodate the long list. When I click the "Switch" button to display div1 instead and hide div2, div1 is resized to fit 1<BR>2 perfectly, being much less than 100 x 100.

If, on the other hand, I display div1 first it is 100 x 100. But when switching to div2 it gets more than 100 x 100 without scroll bars..

So.. Is it possible that the javascript code (switch) is faulty? or do I have to add smth.?

I just realized that this works fine in IE, while I'm usually using Firefox.. It doesn't work in Opera too..

Thanks for any advice.

Dani.
danielpaval is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-09-2007, 01:06 PM Re: DIVs RESIZE TD
JamieLewis's Avatar
Pretty Much a Big Deal...

Latest Blog Post:
Gooie
Posts: 385
Name: Jamie Lewis
Location: UK
Trades: 0
That is some of the ugliest code I have ever seen. Please just rewrite it in standardised markup. Once its standardised it will be easy to fix any design issues you have.

Jamie
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
JamieLewis is offline
Reply With Quote
View Public Profile Visit JamieLewis's homepage!
 
Old 08-09-2007, 01:56 PM Re: DIVs RESIZE TD
Novice Talker

Posts: 5
Trades: 0
Man.. It's a few lines of code to prove something. It will not get to NASA and even if it is badly formatted you should understand what a few lines of code do. So don't play hard to get and if you want to help just do it or else let this thread be. Thank you.
danielpaval is offline
Reply With Quote
View Public Profile
 
Old 08-09-2007, 02:02 PM Re: DIVs RESIZE TD
LadynRed's Avatar
Defies a Status

Posts: 10,017
Location: Tennessee
Trades: 0
I'll never understand why people will use divs and CSS and stuff all that into a 1997 table for layout.

What Jamie meant was to ditch the tables and use CSS for layout.

Tables will stretch to fit the width of what's in them - period, that's the way they are. If you dump the tables, then you can have some finer control of the div sizing.
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

LadynRed is offline
Reply With Quote
View Public Profile
 
Old 08-09-2007, 02:34 PM Re: DIVs RESIZE TD
Novice Talker

Posts: 5
Trades: 0
OK. The thing is that I'm working on a legacy web application which is table based and I use CSS and Javascript to make it sharper. I only recently heard of the CSS no-table trend, but it is not the right moment to look more into it. And if you look closer to my problem the table has little to do with it. It is actually a combination of CSS and Javascript on divs that works right in IE but fails in Firefox and Opera. I understand that you guys dislike tables. Maybe I do to, but there is a problem that I have to fix and I do not have the time to argue on trends and patterns. I appreciate your recommendations though.
danielpaval is offline
Reply With Quote
View Public Profile
 
Old 08-09-2007, 02:55 PM Re: DIVs RESIZE TD
LadynRed's Avatar
Defies a Status

Posts: 10,017
Location: Tennessee
Trades: 0
No, it works WRONG in IE for various reasons - mainly the raft of BUGS in that browser. Firefox and Opera are more standards-compliant and are therefore showing you the CORRECT rendering.

Be that as it may, I understand your predicament with a legacy site.
Have you tried giving the table itself a fixed width equal to what you want ?

I"m not a script guru so I can't speak to the scripting, but you may have to TELL it in the script to re-size the table back to the original desired size.
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

LadynRed is offline
Reply With Quote
View Public Profile
 
Old 08-09-2007, 02:55 PM Re: DIVs RESIZE TD
Novice Talker

Posts: 5
Trades: 0
Here are the divs without a table containing them. The problem persists: When a div is switched from display:none to display:inline it does not respect the given height, width and overflow style.

Code:
            <div id="div1" style="width:100px;height:100px;overflow:auto;display:none">
                1<br>
                2<br>
            </div>
            <div id="div2" style="width:100px;height:100px;overflow:auto">
                1<br>
                2<br>
                3<br>
                4<br>
                5<br>
                6<br>
                7<br>
                8<br>
                9<br>
                10<br>
                11<br>
                12<br>
                13<br>
                14<br>
                15<br>
                16<br>
                17<br>
                18<br>
                19<br>
                20<br>
            </div>


<script type="text/javascript">
    function s() {
        if (document.getElementById("div1").style.display == "none") {
            document.getElementById("div1").style.display = "inline";
            document.getElementById("div2").style.display = "none";
        } else {
            document.getElementById("div1").style.display = "none";
            document.getElementById("div2").style.display = "inline";
        }
    }
</script>

<input type="button" value="Switch" onclick="return s()" />

Last edited by danielpaval; 08-09-2007 at 03:00 PM..
danielpaval is offline
Reply With Quote
View Public Profile
 
Old 08-09-2007, 03:10 PM Re: DIVs RESIZE TD
Novice Talker

Posts: 5
Trades: 0
display:block instead of display:inline and it works! So you call yourselves gurus because you don't like 1997 tables.. No ****!?

Last edited by danielpaval; 08-09-2007 at 03:17 PM..
danielpaval is offline
Reply With Quote
View Public Profile
 
Old 08-09-2007, 06:53 PM Re: DIVs RESIZE TD
ChipJohns's Avatar
I don't know! Do you?

Posts: 488
Name: Chip Johns
Location: Savannah Georgia
Trades: 0
Remember one thing.

The help provided here is FREE..!

I've been in this business for quite a long time and must say that if LadynRed is providing assistance, you are getting help from one of the best their is...

Remember that you have been staring at this code much, much, much longer than the people helping. At one glance, the answer doesn't always just POP UP in our face. If you have been looking at quite a few forums, you have been fretting over this for a bit.

Brainstorming is useful. And often this may be all you get. It is still worth it.

Sometimes when people do things that are a bit "unorthodox" it's not as easy to figure the best way to fix it. Sometimes legacy fixes require this, "unorthodox" fix, but when you are the one doing it you know exactly what you are trying to accomplish. At a forum like this most of the rest are trying to help with 1/10 the information they really need.

Glad you figured it out. Sometimes all we need is a good sounding board. Hopefully your next problem will bring you back. As you said, you just recently learned about tableless layout- this tells me that you are not as accomplished as many of the people here. I don't mean this as a insult.

SO come back and learn more.. you will learn a lot here, that's for sure...

Chip &;-)
ChipJohns is offline
Reply With Quote
View Public Profile Visit ChipJohns's homepage!
 
Reply     « Reply to DIVs RESIZE TD
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29790 seconds with 12 queries