如何划分中间垂直线? [重复]

时间:2023-02-09 15:29:06

This question already has an answer here:

这个问题在这里已有答案:

I have this page:

我有这个页面:

http://invata.dac-proiect.ro/invat/index2.html

http://invata.dac-proiect.ro/invat/index2.html

I want my div .container-home to be align vertically to the center.

我希望我的div .container-home垂直对齐中心。

CODE HTML:

代码HTML:

<div class="container-home" style="width: 900px;height: 696px;background: url(DECUPATE/TEST/images/ppp.jpg);margin: 0 auto;background-size: contain;">
<div class="margine">
<div class="sus">
     <div class="btn"></div>
     <div class="btn2"></div>
</div>

<div class="jos">
     <div class="btn3"></div>
     <div class="btn4"></div>
</div>
</div>


</div>

How do I do this?

我该怎么做呢?

I found these examples but we did not implement them.

我找到了这些例子但我们没有实现它们。

http://www.vanseodesign.com/css/vertical-centering/

http://www.vanseodesign.com/css/vertical-centering/

Thanks in advance!

提前致谢!

EDIT:

编辑:

I add:

我加:

body{display table;}
.container-home{display:table-cell;vertical-align;middle;}

but not working.

但没有工作。

1 个解决方案

#1


0  

You need to use some savvy positioning in your CSS. Add the following to your container-home class in the CSS:

您需要在CSS中使用一些精明的定位。将以下内容添加到CSS中的container-home类:

.container-home {
  /* existing code */
  position:relative;
  top:50%;
  transform:translateY(-50%);
}

The entire body of the page should be vertically and horizontally centered now.

页面的整个主体现在应垂直和水平居中。

#1


0  

You need to use some savvy positioning in your CSS. Add the following to your container-home class in the CSS:

您需要在CSS中使用一些精明的定位。将以下内容添加到CSS中的container-home类:

.container-home {
  /* existing code */
  position:relative;
  top:50%;
  transform:translateY(-50%);
}

The entire body of the page should be vertically and horizontally centered now.

页面的整个主体现在应垂直和水平居中。