You can do something like this:
var width = $(window).width() - 25;
$("#mydiv").width(width);
25 is just a sample number, for example your margin (you can get this dynamically too)
You may also want to wrap it into a function and call this on both page load and on resize
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…