【问题标题】:How to make a wordpress div align to the top of the page?如何使 wordpress div 与页面顶部对齐?
【发布时间】:2016-01-27 20:44:44
【问题描述】:

我正在构建一个带有透明标题的页面模板,并且我正在尝试使 #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;
}

任何关于我做错了什么的建议将不胜感激。

谢谢!

【问题讨论】:

    标签: html css wordpress


    【解决方案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 */
    

    【讨论】:

    • 嗨迈克尔,这只是去掉了标题下方的空白。我刚刚在标题 css 中添加了“z-index:2; position:absolute;”,这有点工作,但现在标题不像内容和页脚那样居中。
    • 抱歉,我在标题下误解了您的请求。您的意思是沿 z 轴,而不是 y 轴。我不清楚这个问题。等等……
    • 嗨迈克尔,很抱歉再次打扰你,但我刚刚注意到这在 safari 上不起作用。它在 Chrome 和 Firefox 上运行良好,但由于某种原因,标头在 Safari 上向右移动。您是否知道解决此问题的方法?
    • 另外,要获取您可能需要的供应商前缀,请在左侧面板中输入您的标准 CSS:autoprefixer.github.io
    • 底线:在transform规则正上方添加这一行代码:-webkit-transform: translateX(-50%);
    猜你喜欢
    • 1970-01-01
    • 2017-01-28
    • 1970-01-01
    • 2023-03-22
    • 2011-04-01
    • 2013-04-04
    • 2013-10-02
    • 1970-01-01
    • 2015-02-12
    相关资源
    最近更新 更多