2012-10-07 39 views
0

我似乎無法在我的.css文件中找到錯誤,以便我的JavaScript顯示在頁面的中心(現在顯示在最左側)。我想將地址和聯繫人置於照片下方。我正在學習JavaScript課程,因此只能使用它,而不是其他程序。CSS和JavaScript顯示

錯誤來自.css.js

HTML:

<!doctype html>  
<html lang="en">  
    <head> 

     <meta charset="utf-8"> 

     <link href="css/armchair.css" rel="stylesheet"> 

    </head> 

    <body> 
     <!-- wrapper section starts --> 
     <div id="wrapper">    

      <!-- header section starts --> 
      <div id="header"> 
       <img src="images/header.jpg" alt="Armchair Logo" width="975" height="230" class="floatcenter"> 
      </div> 
      <!-- header section ends --> 


      <!-- menu section starts -->  
      <div id="menu"> 
       <ul> 
        <li><a href="index.html">Home</a></li> 
        <li><a href="newrelease.html">New Releases</a></li> 
        <li><a href="placeholder.html" >Special Selection</a></li> 
        <li><a href="contact.html" id="current" class="first">Contact</a></li> 
        <li><a href="placeholder.html">On Sale</a></li> 
       </ul> 
      </div> 
      <!-- menu section ends --> 


      <!-- text section starts --> 
      <div id="content"></div> 
      &nbsp;<img src="images/viewcart.jpg" alt="" width="130" height="59" class="floatright" /> 

      <br><br> 

      <img src="images/store.jpg" alt="Armchair Store" width="520" height="347" class="floatcenterb"> 

      <br><br> 


      <div id="contact_details"></div> 

      <script type="text/javascript" src="js/contact.js"></script> 

      <br/> 
     </div> 

     <!-- footer section starts --> 
     <div id="footer"> 
      <p class="bottom">Copyright &copy; 2012 JC Design | All Rights Reserved | <a href="#">Terms and Conditions</a></p> 
     </div> 
     <!-- foot section ends --> 

    <!-- wrapper section starts --> 


    </body> 
</html> 

.css文件:

/*--------------Body-----------------*/ 

html {background-color: #e2e2e2} 

body { 
    color: #000; background: #fff; 
    font-family: "Helvetica Neue",helvetica,arial, sans-serif; 
    font-size: 90%; 
    text-align: left; 
    width: 975px; 
    margin-left: auto; 
    margin-right: auto; 
} 


p { 
    margin-left: 25px; 
    margin-right: 5px; 
    text-align: left; 
    font-size: 110%; 
} 


/*--------------Links formatting------------------*/ 

a:link { 
    background: #fff; color: #7d890d; 
} 


a:visited { 
    color: #034769; 
} 


a:hover { 
    color: #034769; 
    text-decoration: none; 
} 

a:active{ 
    background: #63add0; color: #fff; 
} 

/*Bottom link formatting*/ 

p.bottom a:link { 
    background: #2d1d06; color: #f9b41f; 
} 


p.bottom a:visited { 
    color: #fff; 
} 


p.bottom a:hover { 
    color: #7d890d; 
    text-decoration: none; 
} 
p.bottom a:active{ 
    background: #8742d6; color: #fff; 
} 


/*--------------------Page wrapper----------------*/ 
#wrapper { 
    margin: 0 auto; 
    width: 975px; 
    text-align: left; 
} 

/*Banner styles*/ 

#header { 

    width: 975px; 
    padding-left: 0px; 
    padding-bottom: 10px; 
    padding-top: 0px; 
} 


#footer { 
    clear: both; 
    background: #2d1d06; color: #fff; 
    font-family: "Helvetica Neue",helvetica, arial, sans-serif; 
    font-size: 90%; 
    font-weight: normal; 
    width: 975px; 
    padding-bottom: 3px; 
    padding-top: 3px; 
} 

#footer p { 
    text-align: center; 
} 

#content 
{ 
    margin-left: 15px; 
} 

/*---------------Navigation styles-------------------*/ 

#menu { 
    float: left; 
    margin:0; 
    padding-top: 0px; 
    width: 100%; 
    background: #7d890d; color: #fff; 
} 


#menu ul { 
    margin: 0px; 
    position: relative 
} 


#menu ul li { 
    display: inline; 
} 


#menu ul li a { 
    float: left; 
    padding: 5px 16px; 
    margin-right: 0px; 
    background: #7d890d; color: #fff; 
    text-decoration: none; 
    border-right: 1px solid #e2e2e2; 
} 


#menu ul li a:hover { 
    color: #fff; background: #f9b41f; 
    text-decoration: underline; 

} 

#menu li a#current { 
    background: #ba1212; color: #fff; 
} 



/*-------------Image area--------------*/ 

img 
{ 
    border: 0px 0px ; 
    padding-top: 30px; 
    padding-bottom: 25px; 
    border-radius: 0px; 
} 



.floatcenter { 
    float: left; 
    margin: 0px; 
    padding: 0px; 
    border: none; 
} 

.floatcenterb { 
    margin: 0px 228px; 
    padding: 1px; 
    border: none; 
} 

.floatright 
{ 
    display: block; 
    float: right; 
    margin: 20px; 
    padding: 1px; 
    border: none; 
} 
.floatright2 
{ 
    float: right; 
    margin: 20px; 
    padding: 1px; 
    border: none; 
} 



/*---------------Headings----------------*/ 
hr{ 
    position: relative; 
    width: 90%; 
    margin-left: 25px; 
    margin-right: 25px; 
    color: #3ca0d0; 
    border: 1px; 
    border-style: dotted; 
} 

h1{ 
    color: #2d1d06; 
    font-size: 140%; 
    font-weight: normal; 
    margin-left: 25px; 

} 

h2{ 
    color: #2d1d06; 
    font-weight: normal; 
    font-size: 130% ; 
    text-align: center; 
    text-decoration: underline; 
    margin-left: 0px; 
} 

h3{ 
    font-size: 120%; 
    color: #2d1d06; 
    font-weight: bold; 
    text-align: left; 

} 

h4{ 
    font-size: 120%; 
    color: #2d1d06; 
    font-weight: normal; 
    text-align: center; 

} 

h5{ 
    font-size: 110%; 
    color: #7d890d; 
    width: 70px; 
    margin-bottom: 0px; 
    margin-top: 0px; 
    font-weight: bold; 
    text-align: left; 

} 

/* Table styling */ 

table { 
    border: 1px; 
    border-collapse:collapse; 
    width: 90%; 
    margin-left: 25px; 
    margin-right: 25px; 
    font-size: 90%; 

} 

th { 
    background-color: #000; 
    color: #FFF; 
} 

td { 
    padding: 2px 4px; 
    padding-top: 25px; 

    text-align: left; 
    border-bottom: 0px; 
} 


/*contact page*/ 

fieldset 
{ 
    margin: 10px 25px; 
    padding: 5px 10px; 
    border: 1px solid #3697B5; 
    background:#fff; 
    text-align: center; 
} 

legend 
{ 
    font-size: 80%; 
    color: #000; background: #fff; 
    font-weight:bold; 
    margin-left: 25px; 
} 



label 
{ 
    float: left; /* labels and input fields line up horizontally */ 
    width: 200px; 
    margin-left: 25px;  
    text-align: center; 
} 

textarea 
{ 

    margin-left: 25px; 
} 

.js文件:

//contact.js - this will dipaly all contact detials on the home page and contact us page// 

var Addre = new Array("7945", "Town Plaza", "Vancouver", "E5T 4J9","Canada"); 
var phoneNo = new Array("1-604-568-4938", "Toll free: 1-888-987-4738"); 
var eMail = new Array("[email protected]"); 

// get the HTML div element 
var elem = document.getElementById("contact_details"); 

// display Address 
elem.innerHTML ="Address: <br />"; 
for (var i = 0; i < Addre.length; i++) 
{ 
    if (i > 0) 
     elem.innerHTML += ", "; 
    elem.innerHTML += Addre[i]; 
} 

// display Phone no 

elem.innerHTML += "<br /><br />Contact No:<br /> "; 
for (var i = 0; i < phoneNo.length; i++) 
{ 
    if (i > 0) 
     elem.innerHTML += " or "; 
    elem.innerHTML += phoneNo[i]; 
} 

// display Email 

elem.innerHTML += "<br /><br />Email:<br /> "; 
for (var i = 0; i < eMail.length; i++) 
{ 
    if (i > 0) 
     elem.innerHTML += ", "; 
    elem.innerHTML += eMail[i]; 
} 
+0

爲什麼不使用Javascript原型呢? –

+2

使用[JsFiddle](http://JsFiddle.net) – Lior

+0

你想在頁面的中心顯示什麼?是的,正如@ user1718294所說,使用Fiddle! –

回答

1

剛剛成立text-align: center;在你的CSS爲#contact_details,要追加元素您的聯繫信息:

#contact_details { 
    text-align: center; 
} 

使用你的代碼工作示範見this JS Bin

報價Mozilla's Developer Network page on the 'text-align' CSS property

的文本對齊CSS屬性描述怎麼樣的文本內容內嵌在其父塊元素對齊。文本對齊不控制塊元素本身的對齊方式,僅控制其內聯內容。

初始值:啓動,或作爲左如果方向是LTR,右如果方向是RTL如果不是由瀏覽器支持的無名值。