The resizing matches the font size not the container style body min height 600px box wrapper position absolute transform origin 50 50 user select none width auto height 100px left 110px top 110px width auto height auto display inline block border 1px dashed orange font size 40px white space nowrap dot height 5px width 5px background color 1E88E5 position absolute border radius 0px border 1px solid white user select none transition delay 0 2s opacity 0 box wrapper hover dot box wrapper hover rotate link transition delay 0 0s opacity 1 dot hover background color 0D47A1 rotate link position absolute width 1px height 15px background color 1E88E5 top 20px left calc 50 0 5px z index 1 opacity 0 transition delay 0 2s dot left top top 5px left 5px cursor nw resize dot left bottom bottom 5px left 5px cursor sw resize dot right top top 5px right 5px cursor ne resize dot right bottom bottom 5px right 5px cursor se resize dot top mid top 5px left calc 50 5px cursor n resize dot left mid left 5px top calc 50 5px cursor w resize dot right mid right 5px top calc 50 5px cursor e resize dot bottom mid bottom 5px left calc 50 5px cursor s resize dot rotate top 30px left calc 50 5px cursor url https findicons com files icons 1620 crystal_project 16 rotate_ccw png auto style p id info style position absolute right 20px top 20px p script function clearinfo document getElementById info innerHTML let infos function info id val let s infos id val Object keys infos forEach k s k infos k substring 0 6 br document getElementById info innerHTML s info info 0 1 script div class box wrapper div style position relative background color red display inline block contentEditable true Test TEXT div div class dot rotate div div class dot left top div div class dot left bottom div div class dot top mid div div class dot bottom mid div div class dot left mid div div class dot right mid div div class dot right bottom div div class dot right top div div class rotate link div div script function addDrag elm let elmt elm let initX initY mousePressX mousePressY function repositionElement xx yy elmt style left xx px elmt style top yy px drag support elmt addEventListener mousedown function event if event target className indexOf dot 1 return initX this offsetLeft initY this offsetTop mousePressX event clientX mousePressY event clientY function eventMoveHandler event repositionElement initX event clientX mousePressX initY event clientY mousePressY window addEventListener mousemove eventMoveHandler false window addEventListener mouseup function eventEndHandler window removeEventListener mousemove eventMoveHandler false window removeEventListener mouseup eventEndHandler false false function addRotate elm let elmt elm elmt style transform origin left top elmt style transform origin center center handle rotation let rotatedot elmt querySelector rotate rotatedot addEventListener mousedown function event initX this offsetLeft initY this offsetTop mousePressX event clientX mousePressY event clientY let arrow elmt querySelector box let arrowRects elmt getBoundingClientRect let arrowX arrowRects left arrowRects width 2 let arrowY arrowRects top arrowRects height 2 function eventMoveHandler event let angle Math atan2 event clientY arrowY event clientX arrowX Math PI 2 rotateBox angle 180 Math PI window addEventListener mousemove eventMoveHandler false window addEventListener mouseup function eventEndHandler window removeEventListener mousemove eventMoveHandler false window removeEventListener mouseup eventEndHandler false false function rotateBox deg elmt style transform rotate deg deg elmt rotation deg end addRotate function addResize elm let elmt elm handle resize let rightMid elmt querySelector right mid let leftMid elmt querySelector left mid let topMid elmt querySelector top mid let bottomMid elmt querySelector bottom mid let leftTop elmt querySelector left top let rightTop elmt querySelector right top let rightBottom elmt querySelector right bottom let leftBottom elmt querySelector left bottom rightMid style background color green rightMid addEventListener mousedown e resizeHandler e false false true false leftMid addEventListener mousedown e resizeHandler e true false true false topMid addEventListener mousedown e resizeHandler e false true false true bottomMid addEventListener mousedown e resizeHandler e false false false true leftTop addEventListener mousedown e resizeHandler e true true true true rightTop addEventListener mousedown e resizeHandler e false true true true rightBottom addEventListener mousedown e resizeHandler e false false true true leftBottom addEventListener mousedown e resizeHandler e true false true true function resize w h elmt style width w px elmt style height h px function getCurrentRotation el let st window getComputedStyle el null let tm st getPropertyValue webkit transform st getPropertyValue moz transform st getPropertyValue ms transform st getPropertyValue o transform st getPropertyValue transform none if tm none let values tm split 1 split 0 split let angle Math round Math atan2 values 1 values 0 180 Math PI return angle 0 angle 360 angle return 0 function resizeHandler event left false top false xResize false yResize false initX elmt offsetLeft initY elmt offsetTop mousePressX event clientX mousePressY event clientY initW elmt offsetWidth initW parseFloat window getComputedStyle elmt width initH elmt offsetHeight initH parseFloat window getComputedStyle elmt height initWText parseFloat window getComputedStyle elmt children 0 width initHText parseFloat window getComputedStyle elmt children 0 height console log initW initW info initW initW initFontSize parseFloat window getComputedStyle elmt fontSize initFontSize window getComputedStyle el null getPropertyValue font size info initFontSize initFontSize initCX initX initW 0 5 initCY initY initH 0 5 initRotate getCurrentRotation elmt let initRadians initRotate Math PI 180 let cosFraction Math cos initRadians let sinFraction Math sin initRadians function eventMoveHandler event let wDiff event clientX mousePressX let hDiff event clientY mousePressY let rotatedWDiff cosFraction wDiff sinFraction hDiff let rotatedHDiff cosFraction hDiff sinFraction wDiff if xResize yResize rotatedHDiff 0 if yResize xResize rotatedWDiff 0 let newW initW rotatedWDiff let newH initH rotatedHDiff let newCX initX initW rotatedWDiff 0 5 let newCY initY initH rotatedHDiff 0 5 let dw initW newW let dh initH newH let xx0 initCX cosFraction initW sinFraction initH 0 5 let yy0 initCY cosFraction initH sinFraction initW 0 5 let xx newCX cosFraction newW sinFraction newH 0 5 let yy newCY cosFraction newH sinFraction newW 0 5 let dx xx xx0 let dy yy yy0 let newX initX dx let newY initY dy if top newY dh newH 2 dh if left newX dw newW 2 dw elmt style left newX px elmt style top newY px elmt style width newW px elmt style height newH px console log font size newW initW 100 let percX initFontSize newW initW let percY initFontSize newH initH if xResize yResize percY 0 if yResize xResize percX 0 if it s corder just use the x if xResize yResize percY 0 let perc percX percY info delta perc let sss perc console log font size perc info font size sss elmt style font size sss px console log new width parseFloat window getComputedStyle elmt width elmt width parseFloat window getComputedStyle elmt width px console log new offsetWidth elmt offsetWidth info newwidth newW info textwidth parseFloat window getComputedStyle elmt children 0 width elmt style width parseFloat window getComputedStyle elmt children 0 width px elmt style height parseFloat window getComputedStyle elmt children 0 height px end eventMoveHandler window addEventListener mousemove eventMoveHandler false window addEventListener mouseup function eventEndHandler window removeEventListener mousemove eventMoveHandler false window removeEventListener mouseup eventEndHandler false end addResize let ref document getElementsByClassName box wrapper 0 let box2 ref cloneNode true document body appendChild box2 addRotate box2 addResize box2 addDrag box2 box2 style left 300px box2 style top 300px box2 style width 200px box2 style height 100px addResize ref addDrag ref addRotate ref addRotate ref addResize ref addDrag ref ref style left 100px ref style top 100px ref style width 200px ref style height 100px console log ready script
e resizeHandler e true false true false topMid addEventListener mousedown e resizeHandler e false true false true bottomMid addEventListener mousedown e resizeHandler e false false false true leftTop addEventListener mousedown e resizeHandler e true true true true rightTop addEventListener mousedown e resizeHandler e false true true true rightBottom addEventListener mousedown e resizeHandler e false false true true leftBottom addEventListener mousedown e resizeHandler e true false true true function resize w h elmt style width w px elmt style height h px function getCurrentRotation el let st window getComputedStyle el null let tm st getPropertyValue webkit transform st getPropertyValue moz transform st getPropertyValue ms transform st getPropertyValue o transform st getPropertyValue transform none if tm none let values tm split 1 split 0 split let angle Math round Math atan2 values 1 values 0 180 Math PI return angle 0 angle 360 angle return 0 function resizeHandler event left false top false xResize false yResize false initX elmt offsetLeft initY elmt offsetTop mousePressX event clientX mousePressY event clientY initW elmt offsetWidth initW parseFloat window getComputedStyle elmt width initH elmt offsetHeight initH parseFloat window getComputedStyle elmt height initWText parseFloat window getComputedStyle elmt children 0 width initHText parseFloat window getComputedStyle elmt children 0 height console log initW initW info initW initW initFontSize parseFloat window getComputedStyle elmt fontSize initFontSize window getComputedStyle el null getPropertyValue font size info initFontSize initFontSize initCX initX initW 0 5 initCY initY initH 0 5 initRotate getCurrentRotation elmt let initRadians initRotate Math PI 180 let cosFraction Math cos initRadians let sinFraction Math sin initRadians function eventMoveHandler event let wDiff event clientX mousePressX let hDiff event clientY mousePressY let rotatedWDiff cosFraction wDiff sinFraction hDiff let rotatedHDiff cosFraction hDiff sinFraction wDiff if xResize yResize rotatedHDiff 0 if yResize xResize rotatedWDiff 0 let newW initW rotatedWDiff let newH initH rotatedHDiff let newCX initX initW rotatedWDiff 0 5 let newCY initY initH rotatedHDiff 0 5 let dw initW newW let dh initH newH let xx0 initCX cosFraction initW sinFraction initH 0 5 let yy0 initCY cosFraction initH sinFraction initW 0 5 let xx newCX cosFraction newW sinFraction newH 0 5 let yy newCY cosFraction newH sinFraction newW 0 5 let dx xx xx0 let dy yy yy0 let newX initX dx let newY initY dy if top newY dh newH 2 dh if left newX dw newW 2 dw elmt style left newX px elmt style top newY px elmt style width newW px elmt style height newH px console log font size newW initW 100 let percX initFontSize newW initW let percY initFontSize newH initH if xResize yResize percY 0 if yResize xResize percX 0 if it s corder just use the x if xResize yResize percY 0 let perc percX percY info delta perc let sss perc console log font size perc info font size sss elmt style font size sss px console log new width parseFloat window getComputedStyle elmt width elmt width parseFloat window getComputedStyle elmt width px console log new offsetWidth elmt offsetWidth info newwidth newW info textwidth parseFloat window getComputedStyle elmt children 0 width elmt style width parseFloat window getComputedStyle elmt children 0 width px elmt style height parseFloat window getComputedStyle elmt children 0 height px end eventMoveHandler window addEventListener mousemove eventMoveHandler false window addEventListener mouseup function eventEndHandler window removeEventListener mousemove eventMoveHandler false window removeEventListener mouseup eventEndHandler false end addResize let ref document getElementsByClassName box wrapper 0 let box2 ref cloneNode true document body appendChild box2 addRotate box2 addResize box2 addDrag box2 box2 style left 300px box2 style top 300px box2 style width 200px box2 style height 100px addResize ref addDrag ref addRotate ref addRotate ref addResize ref addDrag ref ref style left 100px ref style top 100px ref style width 200px ref style height 100px console log ready script