Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 显示表格单元格宽度工作不正常_Html_Css - Fatal编程技术网

Html 显示表格单元格宽度工作不正常

Html 显示表格单元格宽度工作不正常,html,css,Html,Css,除非使用像素宽度,否则无法使元素与其父元素的宽度相同 这是正在发生的事情的例子: 示例HTML <body> <div class="some-class"> <div> <p>Some text</p> </div> </div> </body> 基本思想是将文本集中在中。如果我丢弃并将文本保留在中(通过设置显示:表格单元格),则水平居中有效,但垂直居中无效。如

除非使用像素宽度,否则无法使
元素与其父元素的宽度相同

这是正在发生的事情的例子:

示例HTML

<body>
  <div class="some-class">
    <div>
      <p>Some text</p>
    </div>
  </div>
</body>
基本思想是将文本集中在
中。如果我丢弃
并将文本保留在
中(通过设置
显示:表格单元格
),则水平居中有效,但垂直居中无效。如果我喜欢我提供的JSFIDLE,那么
元素的宽度不够大,无法进行水平居中


有什么想法吗?

Miss
中显示
。一些类div

.some-class div {
    display: table;
}
你可以试试

.some-class div p {
  display: block;
  width: 100%;
  height: 100%;
  text-align: center;
  line-height: 24vw;
  margin: 0px;
}
但是如果你有超过1行的文本,那就不贵了

第二种解决方案:

.some-class div p{
  position: absolute;
  display:block;
  width: 100%;
  height: 20px;
  top:50%;
  margin-top: -10px;
  text-align:center;
}

如果你有线缠绕,效果会更好,但是如果超过2条线,它就不能正确居中了。现在又试了一次。无论是在JSFIDLE中还是在真实情况下都不起作用。@JitendraPancholi谢谢-这很有效!我试错了父母。我怎么能接受你们的答案呢?第二个解决方案将有50%-10px的最高位置,不知道你们有多少行,但至少所有的行都在盒子里。
.some-class div p{
  position: absolute;
  display:block;
  width: 100%;
  height: 20px;
  top:50%;
  margin-top: -10px;
  text-align:center;
}