<!doctype html>
<meta charset="utf-8">
<style>
.test {
  border: 1px solid;
  max-width: max-content;
}

span {
  display: block;
  background-color: green;
}
</style>
<div class="test">
  <span style="width: 40px; height: 40px"></span>
</div>
<div class="test">
  <span style="width: 100px; height: 100px"></span>
</div>
<div class="test">
  <span style="width: 200px; height: 200px"></span>
</div>
