CSS Property Value How to - Use Auto Margin with Auto Width








Question

We would like to know how to use Auto Margin with Auto Width.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.panel {<!-- ww w .  ja va  2  s  . c  o m-->
  border-style: solid;
  border-color: #000000;
}

.item {
  width: 50px;
  height: 50px;
  margin: 30px;
  margin-left: -webkit-calc(50% - 30px);
  margin-left: calc(50% - 30px);
  border-style: solid;
  border-color: #000000;
}
</style>
</head>
<body>
  <div class="panel">
    <div class="item"></div>
  </div>
</body>
</html>

The code above is rendered as follows: