Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/33.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.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 设置表格单元格的px宽度_Html_Css - Fatal编程技术网

Html 设置表格单元格的px宽度

Html 设置表格单元格的px宽度,html,css,Html,Css,我正在为具有“显示表格单元格”属性的div指定宽度,但它不起作用 我的代码是 <header class="header layers"> <div class="wrap"> <h1 id="title"><?php echo $blogtitle;?></h1> </div> </header>

我正在为具有“显示表格单元格”属性的div指定宽度,但它不起作用

我的代码是

<header class="header layers">
        <div class="wrap">
            <h1 id="title"><?php echo $blogtitle;?></h1>
        </div>
</header>
但是我不知道为什么这次不起作用,我已经用了很多次了,没有问题。当我在inspect元素中看到wrap类的宽度时,它将其设置为100%,没有错误。 请帮忙。感谢您的留言和评论


FIDLE链接是注释中要求的,下面是一个使用
display:flex
()垂直对齐文本的示例(正如您尝试使用
display:table cell
)。您还可以像普通块元素一样,轻松指定flexbox的
宽度
高度

如您所见,
display:flex
元素正确地垂直居中文本,并且可以正确地设置为
1040px
宽度

*{
框大小:边框框;
}
html,正文{
身高:100%;
填充:0;
保证金:0;
}
分区#集装箱{
显示器:flex;
对齐项目:居中;
身高:100%;
宽度:1040px;
}
div#居中{
高度:20px;
宽度:100%;
文本对齐:居中;
}

使用
display:flex
垂直居中显示。
为什么不使用
显示:内联块
?这将允许你设置一个宽度。也许看到?我希望H1在中间浮动,这就是为什么我设置显示表格Cype的原因。我如何使用Flex进行垂直对齐。请告诉Jonathan Lam谢谢你great@YashAgarwal没问题!我很高兴我帮了忙!
.layers {
  position: absolute;
  display: table;
  top: 0;
  left: 0;
  overflow: hidden;
  box-sizing: border-box;
  table-layout: fixed;
}

.wrap {
  height: 100%;
  margin-right: auto;
  margin-left: auto;
  overflow: hidden;
  display: table-cell;
  vertical-align: middle;
  width: 1040px;
}

.header {
  height: 80px;
  width: 100%;
}

#title {
  font-size: 30px;
  color: black;
  font-family: 'Roboto', sans-serif;
}