Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent padded child element to overflow its parent?

As you can see from this example, the input seems to "overflow" its parent div. I'd like to add padding to the input without making it overflow its parent.

I would like to know the best solution/workaround for every browser (including IE, Firefox, Chrome, etc).

like image 576
Ricardo Rodrigues Avatar asked Jun 09 '12 23:06

Ricardo Rodrigues


People also ask

How do I stop a DIV from overflowing the container?

You could simply set the container to flexbox. Another option would be using CSS table, some extra HTML code is needed. And max-height doesn't work with table layout, so use height instead. Save this answer.


1 Answers

You can see this answer, but if you don't like it, you can use box-sizing CSS3 property like this:

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

Live jsFiddle example

like image 110
Fong-Wan Chau Avatar answered Sep 18 '22 12:09

Fong-Wan Chau