Full size centered child

Example of an element that fills its parent and has a percentage margin

by doug65536

HTML

<div class="container">
    <div class="one">Percentage sized and still centered.</div>
</div>
<div class="container">
    <div class="one">Percentage sized and still centered.</div>
</div>

CSS

body {
    background: #900;
    width:100%;
    height:100%;
}

.container {
    width:100%;
    height:50%;
}

.one {
    position: absolute;
    left: 50%;
    top: 50%;
    -webkit-transform: translate(-50%, -50%);
    /*
  This doesn't work
  margin-left: -25%;
  margin-top: -25%;
  */
    width: 40%;
    height: 50%;
    padding: 20px;
    background: red;
    color: white;
    text-align: center;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.2);
}