IMPORTANT
Check out ThirtyDot's response for a solution that does not affect the overall width of the outer element:
How to achieve almost 100% div width
The following code will result in the total width of the outer element being the sum of the width and the padding on the left and right sides, which is not what the question is asking for. Apologies for any confusion caused. :)
To have the #inner element be 10px less in total, you can add a left and right padding of 5px
:
<div id="outer">
<div id="inner"></div>
</div>
#outer {
width: 500px;
height: 500px;
background: red;
padding: 2px 5px;
}
#inner {
width: 100%;
height: 500px;
background: blue;
}
http://jsfiddle.net/ZtaCM/
UPDATE
If you consider the use of the max-width
property, see the following demonstration:
<div id="test">
<div id="outer">
<div id="inner"></div>
</div>
</div>
<p>
<input type="button" onclick="changeWidth('400px')" value="Change to 400px"/>
<input type="button" onclick="changeWidth('500px')" value="Change to 500px"/>
<input type="button" onclick="changeWidth('600px')" value="Change to 600px"/>
</p>
#outer {
width: 100%;
max-width: 500px;
background: red;
padding: 2px 5px;
}
#inner {
width: 100%;
height: 200px;
background: blue;
}
#test {
background: yellow;
width: 600px;
}
function changeWidth(width) {
document.getElementById('test').style.width = width;
}
http://jsfiddle.net/ZtaCM/1/