Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

box-sizing border appear on hover contents moving

Tags:

html

css

code:

   <div class="block">

    </div>

div.block
{
   box-sizing: border-box;
}
div.block:hover
{
   border: 1px solid orange;
}

When hovering the block with the use of box-sizing, the contents inside is moving, how to prevent this?

like image 578
Hello Avatar asked Dec 04 '25 16:12

Hello


2 Answers

div.block {
   box-sizing: border-box;
   border: 1px solid [your bg color];

}
div.block:hover {
   border: 1px solid orange;
}

Try this :)

When you hover it adds a border. So its making extra pixels. If you add a border to original item(this case block) IT wont have to add new pixels, as they already exsist.

As said below: border 1px solid transperparent wil work fine to

like image 165
DiederikEEn Avatar answered Dec 08 '25 14:12

DiederikEEn


Add padding and then remove equal to border pixels when hovering.

div.block
{
   box-sizing: border-box;
   padding: 10px;
}
div.block:hover
{
   border: 1px solid orange;
   padding: 9px;
}
like image 20
Nicklas Barklund Avatar answered Dec 08 '25 13:12

Nicklas Barklund



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!