CSS: Responsive way to center a fluid div (without px width) while limiting the maximum width?

前端 未结 6 910
Happy的楠姐
Happy的楠姐 2020-12-04 12:54

I\'ve seen a million questions about how to center a block element and there seem to be a couple popular ways to do it, but they all rely on fixed pixels widths. Then either

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-04 13:10

    This might sound really simplistic...

    But this will center the div inside the div, exactly in the center in relation to left and right margin or parent container, but you can adjust percentage symmetrically on left and right.

    margin-right: 10%;
    margin-left: 10%;
    

    Then you can adjust % to make it as wide as you want it.

提交回复
热议问题