如何使wordpress div对齐到页面顶部?

时间:2016-01-03 22:19:13

标签: html css wordpress

我正在构建一个带有透明标题的页面模板,并且我试图让#content div对齐到页面顶部,标题下方。

我尝试过css,例如:

position:absolute; 
top:0; 
left:0;

到目前为止还没有一个有效..

以下是我的页面模板样式表,相关页面为:

.wrapper {
    min-width: 100%;    
    height: auto !important; 
}

.header {
    background-color:transparent;
    width: 75%;
    max-width: 75%;
    height: 40px;
    padding-top: 32px;
    padding-bottom:32px;
    margin-right: auto;
    margin-left: auto;  
}

#content {
    position: absolute;
    top:0;
    left:0;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    font-style: normal;
    font-weight: light;
    color: #ffffff;
    background-color: #ffffff;
    height: auto;
    width: 100%;
    max-width:100%;
    min-width: 960px;
    margin-top: -50px;
    margin-left: auto;
    margin-right: auto;
    text-align: left;
    line-height: 30px;
}

对于我做错的任何建议都将不胜感激。

谢谢!

1 个答案:

答案 0 :(得分:1)

试试这个:

#content {
    position:absolute; 
    top: 0; 
    left: 0;
    right: 0;
    bottom: 0;
}

.header {
    z-index: 2;
    position: absolute;
    /* background-color: transparent; <-- not necessary */
    width: 75%;
    max-width: 75%;
    height: 40px;
    padding-top: 32px;
    padding-bottom: 32px;
    /* margin-right: auto; <-- not necessary */
    /* margin-left: auto;  <-- not necessary */
    left: 50%; /* new; center header horizontally */
    transform: translateX(-50%); /* new; fine tune horizontal centering */
相关问题