Make button width fit to the text

后端 未结 8 593
一生所求
一生所求 2020-12-29 20:29

While I was fiddling with this \'Fancy 3D Button\' example, I found that the width seemed to be hard-coded to fit the text\'s width.

Here is the HTML /

8条回答
  •  生来不讨喜
    2020-12-29 21:23

    Remove the width and display: block and then add display: inline-block to the button. To have it remain centered you can either add text-align: center; on the body or do the same on a newly created container.

    The advantage of this approach (as opossed to centering with auto margins) is that the button will remain centered regardless of how much text it has.

    Example: http://cssdeck.com/labs/2u4kf6dv

提交回复
热议问题