-1

I have a text element with textContent "Design", that was transformed with css to be rotated 45 degree. So it get rotated, but the problem is how to get the height of the rotated element. pls refer the img

Rotated

Initial Position

I need the height and width of the box containing the text

Thanks Gowri

Rachel Gallen
  • 27,943
  • 21
  • 72
  • 81
Code Break
  • 137
  • 1
  • 2
  • 7

2 Answers2

0

Check This overflow for a pretty good solution. The bounding box will be the outside dimensions of your rotated object.

EDIT: I should add, this is essentially the same answer as above, but it gives you a bunch of other metrics to go along with your rudimentary bounding box.

Community
  • 1
  • 1
-1

If you've got a rectangle that's not rotated at all (lines are perfectly horizontal/vertical) with width = w and height = h, then you rotate it by 45 degrees, it should be possible to draw a square which contains this rectangle with width/height = x.

I work out that the size of x in relation to w and h should then be:

x = sqrt(pow(w, 2) / 2) + sqrt(pow(h, 2) / 2)

Hope that's what you were looking for =]

Pudge601
  • 2,048
  • 1
  • 12
  • 11