CSS Property Value How to - box-sizing: border-box;








Question

We would like to know how to box-sizing: border-box;.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#wrapper {<!-- ww w  .j  ava 2s .  c  o  m-->
  width: 60%;
  background-color: #aaa;
  margin: 50px auto;
  line-height: 0;
}

#wrapper img {
  width: 100%;
  border: 1px dashed red;
  box-sizing: border-box;
  margin
}
</style>
</head>
<body>
  <div id="wrapper">
    <img src="http://placehold.it/200x200" />
  </div>
</body>
</html>

The code above is rendered as follows: