Example with flexbox
*{margin:0}
.img
{
background: url(https://proxy.duckduckgo.com/iu/?u=https%3A%2F%2Fih0.redbubble.net%2Fimage.236642016.7494%2Fap%2C550x550%2C12x16%2C1%2Ctransparent%2Ct.png&f=1);
height: 100vh;
background-size: cover;
}
If you only need your figure to be 100% width, there's easier solution:
*{margin:0}
If you want to do this automatically, the only solution is using javascript:
function changeFigureContent(figure)
{
var width = figure.children('img').width();
figure.children('figcaption').css('width', width)
}
window.addEventListener('load', function(){
$('figure').each(function(k, v){
changeFigureContent($(v));
})
})
*{margin:0}