简体   繁体   中英

DIV table-cell width 100%

Here is my code:

<div style='display: table'>
    <div style='height:200px; width:100%; text-align: center; display: table-cell; vertical-align: middle'>No result found</div>
</div>

Why is that the width:100% is not working? How can I solve it?

Try giving width: 100% to parent so that the child has full width.

<div style='display: table; width:100%; background:#f00;'>
    <div style='height:200px; width:100%; text-align: center; display: table-cell; vertical-align: middle'>No result found</div>
</div>

Try this. Container div must be 100%. Then we can set to child's

<div style="display: table; width: 100%;">
<div style="height: 200px; text-align: center; display: table-cell; vertical-align: middle; width: 100%;">No result found</div>
</div>

Can you try this,

  <!-- it is parent div need to set width for the element -->
 <div style="width:100%;display: table;"> 
   <!-- child div, it used the parent element width if it is not set. you can specifiy your own width, if you want make it small than parent div -->
   <div style='height:200px; width:100%; text-align: center; display: table-cell; vertical-align: middle'>No result found</div>
 </div>

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