I\'m trying to center horizontally an element: jsfiddle
On the child I
You were missing a position relative on your parent, position absolute on the child and the left and top values to help offset the child.
DEMO http://jsfiddle.net/nA355/6/
#parent {
width: 300px;
height: 100px;
background-color: black;
border: 1px solid grey;
position: relative;
}
#child {
position: absolute;
height: 100px;
width: 20px;
left: 50%;
top: 50%;
-webkit-transform: translateX(-50%) translateY(-50%);
-moz-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
background-color:red;
}