tags:

views:

156

answers:

3

How can I get fontSize of element in px or pt? Or can I use any other methods? I need to make the size of <a href="...">MAKE ME BIGGER</a> bigger on 130%, 140%, N% from current size.

A: 

Perhaps the information at this website can help you out. It will allow you to use px or pt to specify a new font size.

Ryan Lewis
Sorry, they use <label style="font-size: 12px">some text</label>. So, they can control size of font at every moment.I cann't control initial sizes of elements.
Sergey Kovalenko
+1  A: 

If you use the em unit instead this is relative to the current size, see; http://www.w3schools.com/css/css_units.asp

1em is equal to the current font size. 2em means 2 times the size of the current font. E.g., if an element is displayed with a font of 12 pt, then '2em' is 24 pt. The 'em' is a very useful unit in CSS, since it can adapt automatically to the font that the reader uses

[EDIT] Your label is part of the anchor, does it have to be? What about if you construct the page with;

<label class="fixed-font">
  <a class="scaled-font">BIGGER TEXT</a> 
  Normal Sized Text
</label>

Then created the styles with scaled-font a child selector of fixed-font e.g.

label.fixed-font { 
  font-size:12px 
} 
label.fixed-font a.scaled-font 
{ 
  font-size:1.6em; 
}
Dave Anderson
ok, it works of course. 2em is like 200%. But it takes initial font size from parent element. So, if we have something like <a id="lnk" href="#" style="fontSize: 250%">, setting $('lnk').style.fontSize = '2em' will decrease current size of element. Or if <a class="some_class" ...> That is the problem: I need to know initial size of font.Hmmm... I'll try to create child label-element for current a-element. I think it will allow to use '2em' or '200%' (:
Sergey Kovalenko
thanx for help. Your answer shown me the way ))
Sergey Kovalenko
I cann't construct the page. The task is: to get all links in given container (or on whole page) and make the text in links bigger on 120% or 253%.
Sergey Kovalenko
A: 

to make the size of text element bigger, insert all content of element in the child span and set to this span style="font-size: N%":

function makeBigger(lnk){
  var Span = document.createElement('span')
  for(var i = lnk.childNodes.length - 1; i >=0; i--){
    Span.insertBefore(lnk.childNodes[i], Span.firstChild)
  }
  Span.style.fontSize = '120%'
  lnk.appendChild(Span)
}

of course, it doesn't work in the constructions like this:

<a ... >MAKE ME BIGGER <label class="some_class_with_fixed_font_size">but not me</label></a>
Sergey Kovalenko
See addition to original answer
Dave Anderson
I've answered there. I cann't construct the page. I have to work with any one.
Sergey Kovalenko