CSS div容器对齐垂直

时间:2015-02-25 18:45:21

标签: html css

我有一个div容器。此容器应垂直对齐。 这是我的代码:



*{
    margin: 0px;
    padding: 0px;
}

body{
    background-color: rgb(25, 81, 118);
}

.text{
    margin-left: auto;
    margin-right: auto;
    width: 70%;
    text-align: justify;
    font-size: 32px;
    color: white;
}
nav{
    width: 100%;    
    background-color: white;
}

ul{
    font-size: 0px;
}

<!DOCTYPE html>
<html>
    <head>
        <link href="css.css" type="text/css" rel="stylesheet">
        <meta charset="utf-8"> 
    </head>
    <body>
        
        <div class="text"><p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p></div>
    </body>
</html>
&#13;
&#13;
&#13; .................................................. .................................................. .................................................. .................................................. ..........

2 个答案:

答案 0 :(得分:2)

以下是Click here for JSFiddle

.text {
    width: 70%;
    text-align: justify;
    font-size: 22px;
    color: white;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

答案 1 :(得分:0)

vertical-align:middle添加到div