Prevent the Element Edge from growing when using Transform:Scale

Asked

Viewed 69 times

3

It’s a very simple question, but I couldn’t find an answer...

I have an element that has a borda of 1px. But when I make one :hover on it I apply a transform:scale() but the width of borda him tb seems to increase, until I tried to put 0.01px, but it didn’t work out.

Has some way to fix it without having to create a pseudo-element?

body {
    margin: 2rem;
}
.box {
    float: left;
    width: 100px;
    height: 100px;
    border: 1px solid #000;
    margin-right: 1rem;
transition: transform 500ms;
}
.box:hover {
    transform: scale(2) translate(25%, 25%);
border: 0.1px solid #000;
}
<div class="box"></div>

  • If the element has a text, it should be affected by scale?

  • @Andersoncarloswoss not necessarily, which is bothering me even the edge growing along with the element, because the internal content of the div I already imagined would grow together

1 answer

5


This is because the transform: scale(2) scale the whole object, including its edge. So that it does not happen, It is more interesting to increase your height and width, but its content will not accompany it. If you really need to use Scale, try changing the border for a box shadow because there is no pixel "broken" but strangely with box shadow works, as in the example:

body {
    margin: 2rem;
}
.box {
    float: left;
    width: 100px;
    height: 100px;
    box-shadow: 0px 0px 0px 1px #000;
    margin-right: 1rem;
    transition: box-shadow 500ms, transform 500ms;
}
.box:hover {
    transform: scale(2) translate(25%, 25%);
    box-shadow: 0px 0px 0px .55px #000;
}
<div class="box"></div>

  • 2

    It is an option worth the hint!

  • I hope I helped. Dispose.

  • 1

    I just find it interesting to replace the half pixels with another unit em, theoretically pixels can and should only be represented by integers.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.