css3: translateX to center element horizontally

前端 未结 4 1991
闹比i
闹比i 2020-12-19 08:01

I\'m trying to center horizontally an element: jsfiddle

On the child I

4条回答
  •  一个人的身影
    2020-12-19 08:47

    You can do it by display flex and justify-content is center.

    Example: http://jsfiddle.net/ugw9o3qp/1/

    #parent {
        display: flex;
        justify-content: center;
        width: 300px;
        height: 100px;
        background-color: black;
        border: 1px solid grey;
    }
    #child {
        height: 100px;
        width: 20px;
        background-color:red;
    }
    

提交回复
热议问题