2012-05-30 42 views
0

正如我的標題所說,我不知道爲什麼CSS可以在標籤標籤以外的任何地方工作。CSS將不會在標籤上工作

這裏是我的文件,註冊登記號:

<!DOCTYPE html> 
<html> 

    <head> 
    <link rel="stylesheet" type="text/css" href="style.css" /> 
    <center> <b> Registration Page </b> </center> 
    </head> 

    <br> 

    <body> 
    <img src = "website_demo_pic_1.jpg" /> 
    <ul class = "SiteMap"> 
     <li> <a href = "index.html" >Home Page</a> 
     <br> 
     <li><a href = "register.html" >Register</a> 
     <br> 
     <li><a href = "login.html" >Log In</a> 
     <br> 
    </ul> 

    <form id = "Form1" action = "submit.php" method = "post"> 
     <p class="whitetext"><label for = "username">Username :</label> 
     <input type = "text" name = "Username" id="username"></p> 
     <p class="whitetext"><label for = "password">Password :</label> 
     <input type = "password" name = "Password" id="password"></p> 

    </form> 
    </body> 
</html> 

這裏是我的登錄代碼:

<!DOCTYPE html> 
<html> 

    <head> 
    <link rel="stylesheet" type="text/css" href="style.css" /> 
    <center> <b> Log In Page </b> </center> 
    </head> 

    <br> 

    <body> 
    <img src = "website_demo_pic_1.jpg" /> 
    <ul class = "SiteMap"> 
     <li> <a href = "index.html" >Home Page</a> 
     <br> 
     <li><a href = "register.html" >Register</a> 
     <br> 
     <li><a href = "login.html" >Log In</a> 
     <br> 
    </ul> 

    <form id = "Form2" action = "submit.php" method = "post"> 
     <label for = "username2">Username :</label> 
     <input type = "text" name = "Username" id="username2"> 
     <br> 
     <label for = "password2">Password :</label> 
     <input type = "password" name = "Password" id="password2"> 
     <br> 

    </form> 

    </body> 
</html> 

這裏是我的CSS文件:

img 
    { 
    width: 100%; 
    } 

    body 
    { 
    background-color: black; 
    } 

    label 
    { 
    width: 4em; 
    float: left; 
    text-align: right; 
    margin-right: 0.5em; 
    display: block 
    } 

    p.whitetext 
    { 
    color: white; 
    } 

    ul.SiteMap 
    { 
    float: left; 
    } 

至於我可以告訴代碼是正確的,但文本框不會排隊,這意味着標籤上會出現一些奇怪的事情。

+1

把你的代碼通過[here](http://validator.w3.org/#validate_by_input) –

回答

1

這裏是你的代碼,稍加修改一個的jsfiddle:http://jsfiddle.net/MzsWH/

我看到有關您的標籤屬性的唯一的事情是,你的標籤寬度太小。標籤內的文字的寬度更長,這會導致其包裹,並使所有內容看起來都很怪異。

我所做的只是將寬度從4em改爲6em。

其次,你的HTML有一些問題。 HEAD標籤中有一個CENTER標籤,你的意思是TITLE嗎?此外,列表元素(LI)標籤之間還有換行BR標籤。我建議Shaquin在他的評論中說,通過W3C驗證器運行你的頁面,這樣你可以幫助更新你的HTML。

我希望有幫助!

乾杯!