Instead of using background-image
you can use img
directly and to get the image to spread all the width of the viewport try using max-width:100%;
and please remember don't apply any padding or margin to your main container div as they will increase the total width of the container. Using this rule you can have a image width equal to the width of the browser and the height will also change according to the aspect ratio. Thanks.
Edit: Changing the image on different size of the window
$(window).resize(function(){_x000D_
var windowWidth = $(window).width();_x000D_
var imgSrc = $('#image');_x000D_
if(windowWidth <= 400){ _x000D_
imgSrc.attr('src','http://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png?v=c78bd457575a');_x000D_
}_x000D_
else if(windowWidth > 400){_x000D_
imgSrc.attr('src','http://i.stack.imgur.com/oURrw.png');_x000D_
}_x000D_
});
_x000D_
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>_x000D_
<div id="image-container">_x000D_
<img id="image" src="http://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png?v=c78bd457575a" alt=""/>_x000D_
</div>
_x000D_
In this way you change your image in different size of the browser.