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

css library

Hi,

I would like to know if there exists a javascript library (at least for
IE and Firefox) that let me get css properties in a more structured way.
I would like to have a css value that seperates the size/length value
from the type. For example:
width: 2.5em
size=2.5
type=em

And most importantly I would like a way to convert each such value into
pixels.

Does it exist? I am aware of the CSSStyleDeclaration and related methods
in Firefox.
If not, is it possible to convert such a value as 2.5em into pixels in
javascript? Sometimes the standard available methods that return pixels
cannot calculate the value I need. For example calculating the border size.

Robert.
Jun 14 '06 #1
2 1212
Robert wrote:
Hi,

I would like to know if there exists a javascript library (at least for
IE and Firefox) that let me get css properties in a more structured way.
I would like to have a css value that seperates the size/length value
from the type. For example:
width: 2.5em
size=2.5
type=em
function getCSSValueAndUnit( cssValue )
{
var bitObj = {};
bitObj.size = cssValue.replace(/[a-z]+/i,'');
bitObj.type = cssValue.replace(/^\d+(.\d+)?/,'');
return bitObj;
}

var cssBits = getCSSValueAndUnit('2.5em');
alert( 'size = ' + cssBits.size + '\n'
+ 'type = ' + cssBits.type);
If it's likely that you'll ever get something like "2.em" (which
shouldn't happen as far as I know unless the value is retrieved from
something other than a DOM object), then you may need:

bitObj.size = cssValue.replace(/\.?[a-z]+/i,'');
bitObj.type = cssValue.replace(/^\d+[.]?(\d+)?/,'');

And most importantly I would like a way to convert each such value into
pixels.


Ah, now that would be a trick! Search the archives, I'm sure there are
some very kludgy methods but you'll likely not be happy with any of them.

[...]

--
Rob
Jun 14 '06 #2
mrhoo
428 256MB
The em value is based on the default body font-size, which is set by the user; either directly in the browser or in the OS display preferences.

firefox always returns it in pixels, but ie and opera can return it in pts or
ems or even percentages or constants-xx-large, for example.

One way to get the pixel size of an em in IE is:
1. create a (visibility hidden) absolutely positioned div with a width of 1em
and a height of auto; font-size of 1em, line-height of 1 and padding and margins of 0.
Append it to the body.
2. append a text node to the div with 2 (space delimited) letters in it:'M M'
3. get the offsetHeight of the div
4. replace the 'M M' with M;
5. get the new offsetHeight
6. the em height in pixels is pretty close to #3-#5
7. remove the div and it's children and save the value
Jun 15 '06 #3

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

Similar topics

2
by: pieter.breed | last post by:
Hi All, The company I work for has traditionally used COM/ActiveX for the solutions that it provides. We are in the process of moving to .NET and a few applications have been written in VB.NET...
3
by: K.S.Liang | last post by:
Hi all, 1> If there are more than one dynamic linking libraries in the file system, how do I know which one is loaded into system? Any C library or system call can tell me which *.so or *.sl is...
1
by: Jim | last post by:
Have fully operational software package developed on VB.NET that worked until Jan 1 2003, with early stage deployments on Oct 10, Oct 23, Nov 11, Dec 12 and Dec 30. When attempted final...
10
by: mwt | last post by:
So in a further attempt to learn some Python, I've taken the little Library program (http://groups.google.com/group/comp.lang.python/browse_thread/thread/f6a9ccf1bc136f84) I wrote and added...
10
by: Julian | last post by:
I get the following error when i try to link a fortran library to a c++ code in .NET 2005. LINK : fatal error LNK1104: cannot open file 'libc.lib' the code was working fine when built using...
20
by: Frank-O | last post by:
Hi , Recently I have been commited to the task of "translating" some complex statistical algorithms from Matlab to C++. The goal is to be three times as fast as matlab ( the latest) . I've...
6
by: =?Utf-8?B?WW9naSBXYXRjaGVy?= | last post by:
Hello, I am using Visual Studio-2003. I created a project to build my library. Since I am using third party libraries as well, I have specified those additional library dependencies in project...
0
by: JosAH | last post by:
Greetings, the last two article parts described the design and implementation of the text Processor which spoonfeeds paragraphs of text to the LibraryBuilder. The latter object organizes, cleans...
0
by: JosAH | last post by:
Greetings, welcome back; above we discussed the peripherals of the Library class: loading and saving such an instantiation of it, the BookMark interface and then some. This part of the article...
16
by: Xiaoxiao | last post by:
Hi, I got a C library, is there a way to view the public function names in this library so that I can use in my C program? Thanks.
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.