How to stop div size from increasing when 1 px border is added to the div with CSS?

Spread the love

Sometimes, we want to stop div size from increasing when 1 px border is added to the div with CSS.

In this article, we’ll look at how to stop div size from increasing when 1 px border is added to the div with CSS.

How to stop div size from increasing when 1 px border is added to the div with CSS?

To stop div size from increasing when 1 px border is added to the div with CSS, we set the box-sizing property.

For instance, we write

textarea {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

to set the box-sizing property to border-box to stop div size from increasing when a border is added to the div.

Conclusion

To stop div size from increasing when 1 px border is added to the div with CSS, we set the box-sizing property.

Leave a Reply

Your email address will not be published.