简体   繁体   中英

Center Span in a table-cell, table-row

I am trying to center the text span in the following table-cell, table-row

<div style="display: table; margin-left: auto; margin-right: auto;">                
   <div style="display: table-cell; width:400px;">
       <div style="display: table-row; text-align: center;">
           <span>
               Test
            </span>
        </div>
    </div>
</div>

jsfiddle ( http://jsfiddle.net/7p3zgne0/ )

table-cell and table-row are inverted.

 <div style="display: table; margin-left: auto; margin-right: auto;"> <div style="display: table-row; width:400px;"> <div style="display: table-cell; text-align: center;"> <span> Test </span> </div> </div> </div> 

It should probably be like this:

<div style="display: table; margin-left: auto; margin-right: auto;">                
  <div style="display: table-row; width:400px;">
    <div style="display: table-cell; text-align: center;">
      <span>
        Test
      </span>
    </div>
  </div>
</div>

Note how the table-cell is inside the table-row . In your code, you have them the other way around.

http://jsfiddle.net/sfcaa3Lk/

<div align="center">
    center aligned content (like a span)
</div>

Apply this to your deepest div node

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM