CSS replacement for

后端 未结 7 879
天涯浪人
天涯浪人 2020-12-18 18:33

I know this question has been asked many times, but I never saw a satisfactory answer. I mean, an answer that actually works.

So, here we go again. Take this jsFiddl

7条回答
  •  太阳男子
    2020-12-18 18:45

    div { width: 400px; text-align: center; }
    table { display: inline-block; }
    

    This should work. Check example here: http://jsfiddle.net/ye7ngd3q/2/

    and if you want elements inside table cell left/right aligned then you can define individual classes and assign to element respectively as show below:

    HTML

    A centered div

    A

    centered
    div
    • A centered div

    CSS

    div { width: 400px; text-align: center; }
    table { display: inline-block; }
    .align-left { text-align: left; }
    .align-right { text-align: right; }
    
    

提交回复
热议问题