473,406 Members | 2,698 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,406 software developers and data experts.

natural width of text

Hi,

I have an onmouseover script that displays a div with some comment. There
are several links getting this onmouseover functionality, all with their own
comment text. Now I want the div to have a max width, but if the natural
width is smaller than the max width, it should get the natural width.
commentObj is the div and commentObj.offsetWidth returns the natural width,
as long as we didn't set it to anything else (it seems). As soon as we set
commentObj.style.width to something, there is no turning back and all
comments are equally wide, and the div doesn't return to a natural width
anymore.

For reference, I copied the function that is executed onmouseover below. The
actual positioning happens in a onmousemove action, but that is not relevant
here.

So, basically, the question is: is there a way to get the natural width of
the div or of the text in it? I expected that the natural width of the div
would reset when I put some new text in, but it doesn't, so I need another
function to get the natural width of the text.

Thanks, best regards,
-Hendri Adriaens.

function showComment(text,obj,move,dark,commentWidth)
{
popUp=true;
moveComment=move;
referrerObj=obj;
referrerObj.onmouseout=hideComment;
commentObj.innerHTML=text;
if (commentWidth!=0)
{
if (commentObj.offsetWidth>commentWidth)
{
commentObj.style.width=commentWidth+"px";
}
}
if (dark)
{
commentObj.style.background="#CCAA55";
}
else
{
commentObj.style.background="#F5EBCE";
}
}
Mar 9 '07 #1
1 1732
Hi,

I found the solution: the div has a max-width style property I didn't know
before. So, the solution is:
commentObj.style.maxWidth=commentWidth;

-Hendri.
Mar 9 '07 #2

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

Similar topics

2
by: Alex Shi | last post by:
In php, is there a way obtain the width of a charactor of a certain font? Alex -- ================================================== Cell Phone Batteries at 30-50%+ off retail prices!...
7
by: Graham J | last post by:
Apologies for the partial post that mysteriously escaped as I was composing. I shall try again. For many years I have been happily and successfully coding tables such that the WIDTH specified...
8
by: BiNZGi | last post by:
Hi I have reduced the problem to this code: <form> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td><input type="text" style="width: 100%;" value="Lorem ipsum dolor...
13
by: pb648174 | last post by:
Whenever I want help on a query, I get told my design is wrong, So this time I'm posting a message during the design phase: How am I going to perfectly design the following? We want to be able...
78
by: Frederick Gotham | last post by:
On modern 32-Bit PC's, the following setup is common: char: 8-Bit short: 16-Bit int: 32-Bit long: 32-Bit "char" is commonly used to store text characters. "short" is commonly used to store...
31
by: Sarita | last post by:
Hello, this might sound stupid, but I got a really nice homepage template which unfortunately is a 3-Column Fixed Width CSS format. Now I don't have any content for the right column and would...
2
by: xtian | last post by:
Hi, I have been having some trouble with getting a column to be a fixed width. I have a table with 11 columns, so it doesn't all fit in a normal browser window. One of the cells has a "?" and then...
10
by: Ben | last post by:
Hi at all I am looking for the natural size of an image I found this function : while ((imgHeight = image.getHeight(this)) == -1 ) { // loop until image loaded
10
by: magnesium | last post by:
I have this under-construction page, If you try and select the link coming from the bottom with your mouse, you'll notice, that before the actual link is selected, the td background will change. you...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.