473,386 Members | 1,803 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,386 software developers and data experts.

DIV text vertical-align solution

Hi,
Up to now, I didn't find a solution to align text in the middle of a inline
neither block box in the vertical direction. That's because the
vertical-align property is not active for many boxes.
And when it is, not all the browsers folow it.
I think there is a general solution in surrounding the box with another box,
using the top property and fixing the top position at the middle of the
surrounding box minus the half height of the box to place.The formula is
parentNode.offsetHeight/2-offsetHeight/2

With IE we can directly code that with css style using
top:expression(formula)
With NS, I don't know to do that with css so I use a script and the result
is :

<html>
<head>
<style type="text/css">
<!--
a { height:70px;width:100px;
font-family: arial;
font-size: 10px;
color: #6666FF;
text-decoration: none;
text-align: center;
float: left;
border: 2px solid #FF0000;
display: block;
cursor:pointer
}
div {
position:relative;
top:expression(parentNode.offsetHeight/2-offsetHeight/2);
text-align: center;
border:1px solid #669900;
height:30px;
display:block
}
-->
</style>
<script language="javascript">
function init(){
for (i=0;i<document.getElementsByTagName('div').length ;i++){
document.getElementsByTagName('div')[i].style.top=((document.getElementsByTa
gName('div')[i].parentNode.offsetHeight/2-document.getElementsByTagName('div
')[i].offsetHeight/2)+"px");
}
}
</script>
</head>

<body onload="init();">

<input type="button" id="exec" value="Execute" onclick="execonclick()">
<input type="text" id="exectxt"
value="document.getElementsByTagName('div')[1].style.top='30px'"
size=100><br>
<input type="button" id="alert" value="Alert" onclick="alertonclick()">
<input type="text" id="alerttxt" value="" size = 100><br>

<br><br><br><br>
<a href="http://www.google.com" target="_self" id="out1"><div >Go to Google
word4 word5</div></a>
<a href="http://www.yahoo.com" style="margin-left:20px" target="_self"
id="out2" ><div>Go to Yahoo word4 word5</div></a>
<br style="clear:left"><br><br><br>
<input type="button" value="Change Top" onclick="init()" >
</body>
<script language="javascript">
//------------
function execonclick() {
eval (document.getElementById("exectxt").value);
}
//------------
function alertonclick() {
alert (eval (document.getElementById("alerttxt").value));
}
// -------
</script>
</html>

I added my personal microdebugger to show how the top setting works.

I came to this problem because I want to use DIV instead of TABLE for
displaying an horizontal menu.
Try that
<table width="200px">
<tr>
<td >Menu1 word1 word2</td><td>Menu2 word1111 word2222222</td>
<tr>
</table>
The TABLE has three wonderful properties :
- the TD has a VALIGN property
- in case of many cells, the TD widths are automatically sized in order to
fill exactly the TABLE width
- Each TD wraps its text content, not only the last one in a row.
Compare to that
<div style="width:200px;height:100px;border:1px solid black" >
<div style="height:100%;float:left;border:1px solid green">Menu1 word1
word2</div>
<div style="height:100%;float:left;border:1px solid yellow">Menu2 word1111
word2222222</div>
</div>

I succeed to find a solution for the first TD property. I have two others to
solve!
Thanks for any help for the two last properties.
Jul 23 '05 #1
0 22608

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

Similar topics

3
by: Mark Carroll | last post by:
I've been wanting web pages that nicely embed images among text. The way I typically do this at the moment is to sprinkle my IMGs through the text as floats, alternating between float: left and...
0
by: GiladP1 | last post by:
Hi, I am trying to create a vertical label or a vertical text box by useing their 'Vertical' property. But the text just disapears. I can manage to get right-to-left text to be vertical but...
1
by: James Dean | last post by:
Can you make vertical text in a richtextbox or is there any way around this like make the string vertical outside the textbox then try to paste it in that way into the textbox?.... *** Sent...
0
by: Stephen Muecke | last post by:
I use the following code to draw vertical text in an ownerdrawn StatusBar The text is drawn top to bottom. Is there a way to have the text drawn bottom to top? Stephen Private Sub...
5
by: Stan McCann | last post by:
Is there a way, or does anyone know if maybe in CSS3, there is a plan to implement vertical rotated text? At http://alamo.nmsu.edu/roundup/schedule.html, in the information I was provided,...
11
by: Edson Peacock | last post by:
I have a report with sub reports, one of the subreports have 12 text boxes that are 2" high and I want them all to grow if one goes to 3" high. If anyone has any suggestions they are very much...
12
by: Boris Borcic | last post by:
Hello, I am trying to use UI Automation to drive an MS Windows app (with pywinauto). I need to scrape the app's window contents and use some form of OCR to get at the texts (pywinauto can't...
4
by: umlv | last post by:
Hi, I have a question about vertical text property for labels. I have set several labels to show vertical text on one of my forms. I had no problems with them on my desktop computer. Now I...
4
by: marfola | last post by:
I'm trying to implement bottom-to-top vertical text using CSS attributes in IE : writing-mode: tb-rl; filter: flipv fliph; But I have encountered the following: the text is...
0
by: yatinbvn | last post by:
hi , my name is yatin i have creating swt text with vertical scroll bar in shell, my question is: vertical scroll bar thumb is still visible in swt text when its size is not increase , i want...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...

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.