Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

100% width minus margin and padding [duplicate]

Tags:

html

css

I have been searching around but I can't find a solution to apply to my own problem.

I am working on a mobile website and need the input boxes to be 100% width of the screen. But I have padding-left: 16px and margin: 5px that makes the boxes go outside of the screen so I have to scroll to the right to see the end of the box. How do I make the boxes 100% minus the padding and margin?

To try it out: http://jsfiddle.net/wuSDh/

like image 582
Joakim Melin Avatar asked Jul 13 '13 15:07

Joakim Melin


1 Answers

You can use calc, modern browsers support it and IE9+ as well.

div {   margin: 10px;   width: calc(100% - 20px);   height: 10px;   background: teal; }
<div></div>

Browser support

like image 105
Jonathan Avatar answered Oct 03 '22 22:10

Jonathan