How can I change sizes in pixels of a div and all its child elements?

Discussion in 'CSS' started by SoftLink, Jul 1, 2024.

  1. #1
    I'm trying to perform something like a zoom or scale function but I need to be able to retrieve the new top, left, width and height values in pixels.

    I tried scale and visually it transformed everything in the div but when I checked the computed styles they were unchanged.

    How can I scale a div and all it's child elements, then in javascript retrieve all the new position and dimension style values specifically in pixels?
     
    SoftLink, Jul 1, 2024 IP
  2. SoftLink

    SoftLink Active Member

    Messages:
    141
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    60
    #2
    I've got it: getBoundingClientRect works fine.
     
    SoftLink, Jul 1, 2024 IP
  3. tiantian333

    tiantian333 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    To change the pixel size of ` div ` and all its child elements, you can use CSS's ` transform ` property. By setting the 'scale' value, the entire 'div' can be uniformly scaled. For example, use the following code:
    ```css
    div {
    transform: scale(1.5); /*Magnify 1.5 times*/
    transform-origin: top left; /*Set zoom base point*/
    }
    ```
    In addition, properties such as' font size 'and' padding 'can be adjusted to ensure that the text and margins also change accordingly. In this way, the size of ` div ` and its child elements will be adjusted as a whole.
    Photos To Photos creates fast ID photos and avatars
     
    tiantian333, Mar 25, 2026 at 6:50 PM IP
  4. tiantian333

    tiantian333 Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    To change the pixel size of ` div ` and all its child elements, you can use CSS's ` transform ` property. By setting the 'scale' value, the entire 'div' can be uniformly scaled. For example, use the following code:
    ```css
    div {
    transform: scale(1.5); /*Magnify 1.5 times*/
    transform-origin: top left; /*Set zoom base point*/
    }
    ```
    In addition, properties such as' font size 'and' padding 'can be adjusted to ensure that the text and margins also change accordingly. In this way, the size of ` div ` and its child elements will be adjusted as a whole.
    Photos To Photos creates fast ID photos and avatars
    https://photostophotos.net/
     
    tiantian333, Mar 25, 2026 at 6:51 PM IP