css - 垂直居中一个高度可变的div并显示:none property

标签 css center vertical-alignment

我试图将一个 div 置于另一个 div 的中心。 div 具有可变高度,因为它可能包含更短或更长的文本。此外,由于 div 是一个模态窗口,在 css 中它具有属性 display: none 所以我不能使用 display: table-cell (我认为?)。这是两个 div 的属性:

#page {
height: 100vh;}

.white_content {
display: none;
position: absolute;
left: 36%;
width: 28%;
height: auto;
padding: 16px;
background-color: #ffffff;
z-index: 1002;
overflow: auto;}

这是我的 JSFiddle .

最佳答案

如果将 .white_content 更改为垂直居中

Fiddle demo

.white_content {
    display: block;
    position: absolute;
    left: 36%;
    width: 28%;
    height: auto;
    top: 50%;
    padding: 16px;
    background-color: #ffffff;
    z-index: 1002;
    overflow: auto;
    transform: translateY(-50%): 
}

关于css - 垂直居中一个高度可变的div并显示:none property,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34966976/

相关文章:

html - Bootstrap 3 缩略图 : both vertically and horizontally centered image

css - 为什么我不能使用 CSS 来垂直对齐文本?

html - 如何使用表格单元格在另一个顶部制作 div?

JS 下拉菜单的 CSS 定位 - 相对于流畅的搜索栏宽度

html - 如何在html中并排放置2张图片?

ios 页面 View Controller ,单面,中央书脊

jquery - 垂直对齐 Superslides 中的内容

php - 在移动设备上选择输入文本时,不将输入文本居中

css - 对齐图像和超链接

html - 在网格列内,无论图像位置如何,相对于图像的中心标题