/    Sign up×
Community /Pin to ProfileBookmark

In the following script, how do I get rid of the space between
the top div and the following div sections. I need to know what
to replace the <br> tag with where I stop the floats with “style=’clear:both'”

[code]
<html>
<head>
<title>Slide Tab Menu</title>
<script type=”text/javascript”>

var tabLevel = 0;
var maxLevel = 3;
function Slide(newLevel) {
for (var i=0; i<maxLevel; i++) {
document.getElementById(‘tab’+i).style.display = ‘none’;
}
tabLevel = tabLevel + newLevel;
if (tabLevel >= maxLevel) { tabLevel = maxLevel-1; }
if (tabLevel < 0) { tabLevel = 0; }
document.getElementById(‘tab’+tabLevel).style.display = ‘block’;
document.getElementById(‘infoLine’).innerHTML = ‘Information Line ‘+(tabLevel+1);
}
onload = function() {
Slide(0);
}
</script>
<style type=”text/css”>
.tab {
display:block;
width:250px;
height:100%;
background-color:#ffddbb;
color:#000000;
}
</style>
</head>
<body>

<div id=”main” style=”width:250px;height:300px;”>
<div style=”float:left;width:8%;
background-color:#ffddbb;text-align:center;color:#000000;
cursor:pointer;” onclick=”Slide(-1);”>&nbsp;&lt;&nbsp;
</div>
<div id=”infoLine”
style=”float:left;width:83%;text-align:center;background-color:#ffddbb”></div>
<div style=”float:left;width:8%;
background-color:#ffddbb;text-align:center;color:#000000;
cursor:pointer;” onclick=”Slide(1);”>&nbsp;&gt;&nbsp;
</div>
<!– div style=”clear:both;height:0px;width:0px”></div –>
<br style=”clear:both;”>

<div id=”tab0″ class=”tab”>
<ol>
<li>test</li>
<li>list</li>
<li>contents</li>
</ol>
</div>

<div id=”tab1″ class=”tab”>
<ul>
<li>test 1</li>
<li>list 1</li>
<li>contents 1</li>
</ul>
</div>

<div id=”tab2″ class=”tab”>
<ul style=”list-style-type:none”>
<li>test 2</li>
<li>list 2</li>
<li>contents 2</li>
</ul>
</div>

</div>
</body>
</html>
[/code]

I’m trying to solve one problem at a time,
but my next question will be how to slide the tab body sections into and out of
the area below the top controlling <div> sections. All it does now is
simply hide or show the sections and I would like to create a sliding
illusion if possible. Any ideas on how to control this are appreciated.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@tirnaMay 28.2010 — This is probably closer to what you want regarding removing the gap between the top and lower divs. I had to also widen #main a bit.

The gap is gone in my IE8 and FF3.6

A side issue, I would suggest transferring all the inline styles to the <head>. Imo inline styles make the html messy and difficult to read and debug.

[code=php]<html>
<head>
<title>Slide Tab Menu</title>
<script type="text/javascript">

var tabLevel = 0;
var maxLevel = 3;

function Slide(newLevel) {
for (var i=0; i<maxLevel; i++) {
document.getElementById('tab'+i).style.display = 'none';
}
tabLevel = tabLevel + newLevel;
if (tabLevel >= maxLevel) { tabLevel = maxLevel-1; }
if (tabLevel < 0) { tabLevel = 0; }
document.getElementById('tab'+tabLevel).style.display = 'block';
document.getElementById('infoLine').innerHTML = 'Information Line '+(tabLevel+1);
}
onload = function() {
Slide(0);
}
</script>
<style type="text/css">
.tab {
display:block;
width:250px;
height:100&#37;;
background-color:#ffddbb;
color:#000000;
}
</style>
</head>
<body>

<div id="main" style="width:300px;height:350px;">
<div style="float:left;width:8%; border: 1px solid red;
background-color:#ffddbb;text-align:center;color:#000000; cursor:pointer;" onclick="Slide(-1);">&nbsp;&lt;&nbsp;
</div>
<div id="infoLine" style="float:left;width:50%;text-align:center;background-color:#ffddbb">
</div>
<div style="float:left;width:8%; background-color:#ffddbb;text-align:center;color:#000000;
cursor:pointer;border: 1px solid green" onclick="Slide(1);">&nbsp;&gt;&nbsp;
</div>

<div style="clear:both;" id="tab0" class="tab">
<ol>
<li>test</li>
<li>list</li>
<li>contents</li>
</ol>
</div>

<div id="tab1" class="tab">
<ul>
<li>test 1</li>
<li>list 1</li>
<li>contents 1</li>
</ul>
</div>

<div id="tab2" class="tab">
<ul style="list-style-type:none">
<li>test 2</li>
<li>list 2</li>
<li>contents 2</li>
</ul>
</div>

</div>
</body>
</html>[/code]
Copy linkTweet thisAlerts:
@JMRKERauthorMay 28.2010 — Thanks 'tirna'. I see how you moved the "clear:both" into the following <div>

rather than use the css command within the <br> tag. Makes sense now.

I agree that the <style> section should be, and I usually do, put in the <head> area.

This was just a test and I usually move all the style stuff after I get it working.

I guess I'll just take more time and do it right the first time from now on.

Here's the next version that I'm happy with so far.

<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Slide Tab Menu&lt;/title&gt;
&lt;script type="text/javascript"&gt;
// From: http://www.webdeveloper.com/forum/newreply.php?do=newreply&amp;p=1091735

var tabLevel = 0;
var maxLevel = 3;
function Slide(newLevel) {
for (var i=0; i&lt;maxLevel; i++) {
document.getElementById('tab'+i).style.display = 'none';
}
tabLevel = tabLevel + newLevel;
if (tabLevel &gt;= maxLevel) { tabLevel = maxLevel-1; }
if (tabLevel &lt; 0) { tabLevel = 0; }
document.getElementById('tab'+tabLevel).style.display = 'block';
document.getElementById('infoLine').innerHTML = 'Information Line '+(tabLevel+1);
}
onload = function() {
Slide(0);
}
&lt;/script&gt;

&lt;style type="text/css"&gt;
#main { width:250px; height:300px; }
.tab {
display:block;
background-color:#ffddbb;
width:250px;
height:100&amp;#37;;
color:#000000;
clear:both;
}
.tabCtrl {
float:left;
background-color:#ffddbb;
text-align:center;
cursor:pointer;
color:#000000;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;div id="main"&gt;
&lt;div class="tabCtrl" style="width:8%; border:1px solid green;" onclick="Slide(-1);"&gt;&amp;nbsp;&amp;lt;&amp;nbsp;&lt;/div&gt;
&lt;div class="tabCtrl" style="width:82%" id="infoLine"&gt;&lt;/div&gt;
&lt;div class="tabCtrl" style="width:8%; border:1px solid green;" onclick="Slide(1);"&gt;&amp;nbsp;&amp;gt;&amp;nbsp;&lt;/div&gt;

&lt;div id="tab0" class="tab"&gt;
&lt;ol&gt;
&lt;li&gt;test&lt;/li&gt;
&lt;li&gt;list&lt;/li&gt;
&lt;li&gt;contents&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;

&lt;div id="tab1" class="tab"&gt;
&lt;ul&gt;
&lt;li&gt;test 1&lt;/li&gt;
&lt;li&gt;list 1&lt;/li&gt;
&lt;li&gt;contents 1&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;

&lt;div id="tab2" class="tab"&gt;
&lt;ul style="list-style-type:none"&gt;
&lt;li&gt;test 2&lt;/li&gt;
&lt;li&gt;list 2&lt;/li&gt;
&lt;li&gt;contents 2&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;

&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

Now onto the actual "slide" actions.

Thanks for the help.

?
×

Success!

Help @JMRKER spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...