CSS Transform scale, don't scale child element

前端 未结 3 1980
鱼传尺愫
鱼传尺愫 2021-01-01 13:19

If I have a div with a few child elements and it\'s being css transform scaled. I\'ve got one child element which I don\'t want to scale

相关标签:
3条回答
  • 2021-01-01 13:48

    Unfortunately this is not possible.

    You roughly have two other options though:

    1. Scale all the other elements, excluding the one you don't want to scale (but this won't scale the container).
    2. Scale the container and re-scale the element you don't want to scale (but this will probably make it look blurry).

    Examples:

    // Example 1.
    span:not(:last-child) {
        display: inline-block; /* You can't scale inline elements */
        transform: scale(2);
    }
    
    // Example 2.
    #parent{
        transform: scale(.5);
    }
    
    span:last-child{
        transform: scale(2);
    }
    
    0 讨论(0)
  • 2021-01-01 13:52

    I'm afraid you need to use a more detailed selector, like this #parent > span:not(:last-child). Example.

    0 讨论(0)
  • 2021-01-01 13:53

    I found hack for Chrome to solve problem with blurred.

    #parent { transform: scale(5);}
    #child  { transform: scale(0.2)  translate3d( 0, 0, 0);}
    
    0 讨论(0)
提交回复
热议问题