Answer the question
In order to leave comments, you need to log in
Border adds width to element, how to avoid?
Hello!
There is a grid of blocks, on click I add a class with border: 2px to highlight the selected object. Naturally, the frame adds these two pixels from all sides and the selected object pushes nearby objects away, which makes the grid look crooked.
Are there solutions to fix it?
Answer the question
In order to leave comments, you need to log in
I usually used Box-shadow , and everything works without problems, the box-sizing property solves your problem, well then you need to initially set border: 2px solid transparent for all blocks, and already change the selected element to color, border-color: #333; for example, well, I would advise the shadow, there are no problems with the location on top, bottom or left or right, of course you decide.
use the css property box-sizing: border-box;
htmlbook.ru/css/box-sizing
Use outline A generic
property that simultaneously sets the color, style, and thickness of the outer border on all four sides of an element. Unlike the line specified through the border, the outline property does not affect the position of the box and its width.
more htmlbook.ru/css/outline
Another option is to make a border for all blocks, and only change the color.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question