Html DIV 表格单元格宽度 100%

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19902644/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 15:13:51  来源:igfitidea点击:

DIV table-cell width 100%

htmlcss

提问by user1995781

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?

为什么width:100%不工作?我该如何解决?

回答by Vivek Vikranth

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

尝试给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>

回答by Sridhar R

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

尝试这个。容器 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>

回答by Krish R

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>