/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Line up text … JS or CSS problem?

I want to use the following script like a page index.
The first radio button display shows the contents for the rest of the buttons
The other buttons will be filled in with the contents of its topic.

The program works fine …. except:
The Schedule page left side does not line up with the right side.
It is slightly off, and becomes more off with longer lists.

I believe the cause is that the radio button displays are slightly bigger
than lines with text only. I’ve tried using a style of ‘line-height:xxx’
with different values of ‘xxx’ but I cannot make it truly line up left to right.

I’m not sure if this is a javascript problem or a CSS problem.
Any ideas how I can make the left=right side in vertical height size? ?
Or should I post the question on the CSS forum?

[code=php]
<html>
<head>
<title>Line-Up Lines</title>
<script type=”text/javascript”>

var details = new Array();
var str = ”;
str = ‘Schedule::Choose week of interest’; details[0] = str;
str = ‘Week 1: 1/3 ::Introduction / Case History::More Stuff’; details[1] = str;
str = ‘Week 2: 1/10 ::Visual Acuities::::Distance::Near’; details[2] = str;
str = ‘Week 3: 1/17 ::Color Vision / Stereopsis’; details[3] = str;
str = ‘Week 4: 1/24 ::Hand Neutralization / Autorefraction’; details[4] = str;
str = ‘Week 5: 1/31 ::NPC::NPA::Amp::Versions’; details[5] = str;
str = ‘Week 6: 2/7 ::Patient Observation’; details[6] = str;
str = ‘Week 7: 2/14 ::Professional Communications’; details[7] = str;
str = ‘Week 8: 2/21 ::Confrontation Visual Fields/PD’; details[8] = str;
str = ‘Week 9: 2/28 ::Role Playing’; details[9] = str;
str = ‘Week 10: 3/6 ::Mid terms / No class’; details[10] = str;
str = ‘Week 11: 3/13::Proficiencies/No Class’; details[11] = str;
str = ‘Week 12: 3/20::Spring Break’; details[12] = str;
str = ‘Week 13: 3/27::Open Practice Lab’; details[13] = str;
str = ‘Week 14: 4/3 ::Non-Contact Tonometry’; details[14] = str;
str = ‘Week 15: 4/10::Review / Stamps’; details[15] = str;
str = ‘Week 16: 4/17::Final in Class (all assignments due)’; details[16] = str;
str = ‘Contact Us::Email’; details[17] = str;

tmp = new Array();
str = ”;
for (i=0; i<details.length; i++) {
tmp = details[i].split(‘::’);
str += tmp[1]+'<br />’;
}
details[0] = ‘Schedule::’ + str; // special adjustment for first entry only

function ShowDetails(n) {
var str = details[n]; // alert(str);
var tmp = str.split(‘::’);
tmp.shift();
str = tmp.join(‘<br />’);
return str;
}
function topica(msg) {
document.getElementById(‘TA’).innerHTML = ShowDetails(msg);
}

</script>
</head>
<body onLoad=”topica(0)”>
<TABLE border=”1″ width=”100%”><TR>
<TH width=”65%”>
<fieldset style=”background-color:#ffffcc;”>
<legend><strong>Clinical Optometric Procedures:</strong></legend>

<table width=”100%”> <!– style=”padding: 5px 5px 5px 5px;” –>
<tr>

<td valign=”top” width=”25%”>
<script type=”text/javascript”>
var tmp = new Array();
var str = ”;
for (var i=0; i<details.length; i++) {
tmp = details[i].split(‘::’);
str += ‘<label for=”t’+i+'”><input type=”radio” id=”t’+i+'” name=”point”‘;
str += ‘ onClick=”topica(‘+i+’);” /><span id=”s’+i+'”>’+tmp[0]+'</span></label>’;
str += ‘<br />’;
}
document.write(str);
</script>
</td>
<td valign=”top”>
<div id=”TA” style=”border: none; margin-left: 5px;”> <!– line-height:1.3″ works, sorta –>
</div>
</td>
</tr></table>
</fieldset>

</TH>
<TH>
Calendar will go here
</TH>
</TR></TABLE>

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

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@svidgenDec 15.2007 — Try setting the right-hand DIV's line-height to correlate with the total height of each LABEL on the left and remove the BR's as follows:

[code=html] var str = '';
for (var i=0; i<details.length; i++) {
tmp = details[i].split('::');
str += '<label for="t'+i+'" style="float: left; clear: left; height: 1.5em; margin: 0; padding: 0;"><input type="radio" id="t'+i+'" name="point"';
str += ' onClick="topica('+i+');" /><span id="s'+i+'">'+tmp[0]+'</span></label>';
}[/code]


and

[code=html] <div id="TA" style="border: none; margin-left: 5px; line-height: 1.5;">[/code]

Of course, you can probably use values other than 1.5. But, you get the idea.

This appears to work correctly in FF and IE7. I have not tested in other browsers.

Let me know if that helps!
Copy linkTweet thisAlerts:
@JMRKERauthorDec 15.2007 — ? Thanks 'svidgen', that perfect!

I would not have thought of making the <label> height the same

as the line-height attribute of the <div> tag. Good eyes!!!

I guess it was more of a CSS question that JS but I appreciate the code review.




BTW: Not a problem, but what is the purpose of the

'float: left; clear:left' being back-to back?

I'll use it, just would not have thought of it because I don't know

the reason for setting and immediately clearing attribute.
Copy linkTweet thisAlerts:
@svidgenDec 15.2007 — To be perfectly honest, I'm not 100% sure you need the float/clear left stuff. However, when the float/clear left set of attributes is assigned to a list of items like that, it just lines them up along the left side without the aide (or distraction) of BR's.

Again, I'm not 100% sure you need that. It may work just as well with BR's.
Copy linkTweet thisAlerts:
@JMRKERauthorDec 15.2007 — Thanks again. I'll experiment when I have more time.
×

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,
)...