html - 带表格单元格的 Div 只能使用 1 次

标签 html css

当我用 display:table-cell 制作一个 div 时;它显示像第一张图片。 (这就是我想要的)但是当我添加另一个 div 时它看起来像第二张图片。我只想要第一个 div 下的 div 中间的文本。

这是我的代码

<div id="container">

<div id="over_asero">
    <p id="titel_text"> </p>

    <p id="sub_text"></p>

    <p id="sub_text"></p>
</div>

<div id="veiligheid">
    <p id="titel_text"> </p>

    <p id="sub_text"></p>

    <p id="sub_text"></p>
</div>

#container
{
position: relative;
width: 1140px;
height: 1500px;
margin: auto;
background-color: red;
}

#over_asero
{
position: relative;
width: 1140px;
height: 400px;
top: 150px;
z-index: 2;
display: table-cell;
vertical-align: middle;
}
#over_asero p
{
color: white;
font-family: 'Open Sans', sans-serif;
}
#titel_text
{
font-size: 16px;
}
#sub_text
{
font-size: 12px;
}

#veiligheid
{
position: relative;
width: 1140px;
height: 400px;
top: 550px;
z-index: 2;
background-color: blue;
display: table-cell;
vertical-align: middle;
}

最佳答案

用父div覆盖table-cell div并为其添加显示表格,如下所示

<div class="parent_div">
   <div id="over_asero"></div>
</div>

<div class="parent_div">
   <div id="veiligheid"></div>
</div>

.parent_div{
  display: table;
}

关于html - 带表格单元格的 Div 只能使用 1 次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33012742/

相关文章:

javascript - 如何调整 CSS/JS 中字体的大小,使其相对于其容器的两侧有一定的边距?

css - 单击链接或超链接图像时激活电话 - 给链接或图像 ID 时不起作用?

html - 如何将CSS应用于具有相同类名的DOM元素

html - iOS 网络应用程序 : Hover effect over border

html - 悬停时 li 标签不会下划线

javascript - jQuery 窗口滚动事件不起作用

javascript - 在 ASP.NET 中运行时更改表单 ID 和表单操作

jquery - 如何在 css 中的梯形内插入文本?

javascript - 滑动幻灯片内图像周围出现奇怪的灰色边框

div 上的 CSS 不透明度随时间延迟而不是用户交互变化