这是我的代码:
<div style='display: table'>
<div style='height:200px; width:100%; text-align: center; display: table-cell; vertical-align: middle'>No result found</div>
</div>
为什么width:100%
不起作用?我该如何解决?
答案 0 :(得分:16)
尝试将width: 100%
提供给父母,以便孩子有全宽。
<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>
答案 1 :(得分:2)
试试这个。容器div必须是100%。然后我们可以设置为孩子的
<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>
答案 2 :(得分:0)
你能试试吗,
<!-- 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>