簡體   English   中英

CSS居中嵌套Divs

[英]CSS Centering with nested Divs

誰能看看這個,讓我知道我在做錯什么(可能是愚蠢的事情)?

我希望文本“測試”居中。

http://fiddle.jshell.net/uteaH/3/

CSS:

.wrap {
    max-width: 1139px;
    margin-left: auto;
    margin-right: auto;     }

#screenPresentation {
    border-top: 4px solid #d95936;
    margin-top: 50px;
    margin-bottom:10px;
    background: #fff;
}

#screenPresentation h2 {
    margin-top: -45px;
    color: #000;
    font-size: 2.4em;
    font-weight: 500;
    float:left;
}
 .loginContainer-wrapper {
    width: 99%;
    height: 500px;
    border: 2px solid #000;
    margin:0 auto;
}

HTML:

<div class="wrap" id="screenPresentation">
    <h2>Title</h2>
    <div class="loginContainer-wrapper">
        test
    </div>
</div>

text-align:center; 在任何情況下?

我將在這里成為一個閱讀者,因為您不會告訴我們確切需要集中在哪里

DEMO

對於#screenPresentation h2

去掉
float:left;

用。。。來代替
position: absolute;
width: 95%;
text-align: center;


Sorry - I updated my question. I need the text "test" centered inside the inner div.

那樣的話

#screenPresentation h2移除width:95%;text-align:center
text-align:center添加到.loginContainer-wrapper

DEMO

要使文本居中,您需要執行兩個步驟:

  • 首先重置標簽的marginpadding

     * { margin:0; padding:0; } 
  • 其次添加text-align

     .wrap { text-align:center; } 

演示http://fiddle.jshell.net/uteaH/9/

您可以使用

<center>
test
</center>

會做到的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM