2017-02-12 107 views
0

我試圖重新創建一個網頁文檔使用我的書中提供的步驟。但是,我創建的頁面與本書中的示例不匹配。由於某種原因,標題佔據了我頁面正文的一半。 下面是我試圖模仿這個例子的樣式表。我提供的圖片是我書中的例子。我做錯了什麼?本書example--標題覆蓋身體

enter image description here

下面是HTML和CSS代碼:

/* 
 
    Big J's Deep Dish Pizza style sheet 
 
    Filename: styles.css 
 

 
    Author: Justus Self 
 
    Date:  2/10/2017 
 
    HTML5 and CSS3 Illustrated Unit D, Skills Review 
 
*/ 
 

 
/* body and page container */ 
 

 
/* reset styles */ 
 

 
article, 
 
body, 
 
div, 
 
footer, 
 
header, 
 
h1, 
 
h2, 
 
h3 p { 
 
    border: 0; 
 
    padding: 0; 
 
    margin: 0; 
 
} 
 
.container { 
 
    background-color: black; 
 
    text-align: center; 
 
    max-width: 640px; 
 
    margin: 0 auto; 
 
    position: relative; 
 
} 
 
/* headings */ 
 

 
header { 
 
    background-color: black; 
 
    width: 100%; 
 
    max-width: 640px; 
 
    position: fixed; 
 
    /* z-index: -1; */ 
 
} 
 
header div { 
 
    border: 3px solid red; 
 
    color: white; 
 
    width: 70%; 
 
    margin: 0 auto 0.6em; 
 
} 
 
header p { 
 
    color: black; 
 
    background-color: white; 
 
    border: 3px solid black; 
 
    padding: 6px; 
 
} 
 
header p.phone { 
 
    color: white; 
 
    background-color: black; 
 
    border: 3px solid red; 
 
    padding: 6px; 
 
    width: 50%; 
 
    margin: 0.4em auto; 
 
    clear: both; 
 
} 
 
.established { 
 
    width: 25%; 
 
    float: left; 
 
} 
 
.award { 
 
    width: 25%; 
 
    float: right; 
 
} 
 
.options { 
 
    width: 25%; 
 
    margin: 0 auto; 
 
} 
 
.pointright { 
 
    background-color: black; 
 
    color: red; 
 
    position: absolute; 
 
    top: 0.4em; 
 
    left: 0.4em; 
 
} 
 
.pointleft { 
 
    background-color: black; 
 
    color: red; 
 
    position: absolute; 
 
    top: 0.4em; 
 
    right: 0.4em; 
 
} 
 
/* main content */ 
 

 
article { 
 
    color: black; 
 
    background-color: white; 
 
    text-align: left; 
 
    width: 65%; 
 
    margin: 0 auto; 
 
    padding: 5em 1em 1em; 
 
} 
 
h3 { 
 
    color: red; 
 
    margin: 1em 0 0.4em; 
 
} 
 
.menu { 
 
    margin: 0 0 0.5em; 
 
} 
 
.myo { 
 
    margin-left: 1em; 
 
} 
 
.list { 
 
    margin: 0 0 0 2em; 
 
} 
 
/* footer section */ 
 

 
footer { 
 
    background-color: white; 
 
    color: black; 
 
    border: 3px solid black; 
 
    padding: 0.5em; 
 
}
<!DOCTYPE html> 
 
<html lang="en"> 
 

 
<head> 
 
    <title>Big J&rsquo;s Deep Dish Pizza</title> 
 
    <!-- 
 
     Big J's Deep Dish Pizza main web page 
 
     Filename: index.html 
 
     
 
     Author: Justus Self 
 
     Date:  2/10/2017 
 
     HTML5 and CSS3 Illustrated Unit D, Skills Review 
 
     --> 
 
    <meta charset="utf-8"> 
 
    <meta name="viewport" content="width=device-width"> 
 
    <script src="modernizr.custom.62074.js"></script> 
 
    <link rel="stylesheet" href="styles.css"> 
 
</head> 
 

 
<body> 
 
    <div class="container"> 
 
    <header> 
 
     <div> 
 
     <h1>Big J&rsquo;s Deep Dish Pizza</h1> 
 
     <p>Authentic Chicago-style pies</p> 
 
     </div> 
 
     <p class="established">Established 
 
     <br>1974</p> 
 
     <p class="award">Toronto Times &ldquo;Best Pizza Joint&rdquo;</p> 
 
     <p class="options">Eat in, carry out, or call for delivery</p> 
 
     <p class="phone">(416) 555-3337</p> 
 
     <p class="pointright">&#9755;</p> 
 
     <p class="pointleft">&#9754;</p> 
 
    </header> 
 
    <article> 
 
     <h2>Menu</h2> 
 
     <p class="menu">(prices small/medium/large)</p> 
 
     <h3>Starters</h3> 
 
     <p class="menu">Garlic bread sticks: $5.00</p> 
 
     <p class="menu">Buffalo wings: $6.50</p> 
 
     <p class="menu">House salad: $4.00</p> 
 
     <p class="menu">Caesar salad: $5.50</p> 
 
     <p class="menu">Greek salad: $6.00</p> 
 
     <h3>Deep Dish Pizza</h3> 
 
     <p class="menu">Chicago classic: $15/18/20</p> 
 
     <p class="menu">Meat lover&rsquo;s: $18/22/25</p> 
 
     <p class="menu">Greek: $16/19/22</p> 
 
     <p class="menu">Vegetarian: $15/18/20</p> 
 
     <p class="menu">Make your own (plain cheese): $12/15/18</p> 
 
     <p class="myo">meats: $3/4/5</p> 
 
     <p class="list">sausage, pepperoni, ham, Canadian bacon</p> 
 
     <p class="myo">other toppings: $2/3/4</p> 
 
     <p class="list">mushrooms, onions, green peppers, black olives, fresh tomatoes, extra cheese, garlic, anchovies, fresh spinach, pepperoncini</p> 
 
    </article> 
 
    <footer> 
 
     <p>150 St. Joseph St.</p> 
 
     <p>Toronto, ON M5S 2C3</p> 
 
     <p>(416) 555-3337</p> 
 
    </footer> 
 
    </div> 
 
</body> 
 

 
</html>

+0

[看起來好像沒什麼問題?(http://imgur.com/a/GG35C) – Jhecht

+0

@Jhecht,請注意,您發送的圖片看起來並不像書例子。您發送的圖片是我的代碼創建的。我上傳的照片應該是這樣的。 –

+0

它看起來不像這個例子嗎? – Jhecht

回答

0

我希望這是你指的是什麼。問題有幾個,但最大的問題是有一些奇怪的用法position:fixedposition:absolute。這看起來像你給我們的截圖(即你可以看到「菜單」部分),但不幸的是,它將如何與你的書的其餘部分一起出現,不幸的是,我不知道。

/* 
 
    Big J's Deep Dish Pizza style sheet 
 
    Filename: styles.css 
 

 
    Author: Justus Self 
 
    Date:  2/10/2017 
 
    HTML5 and CSS3 Illustrated Unit D, Skills Review 
 
*/ 
 

 
/* body and page container */ 
 

 
/* reset styles */ 
 

 
article, 
 
body, 
 
div, 
 
footer, 
 
header, 
 
h1, 
 
h2, 
 
h3 p { 
 
    border: 0; 
 
    padding: 0; 
 
    margin: 0; 
 
} 
 
.container { 
 
    background-color: black; 
 
    text-align: center; 
 
    max-width: 640px; 
 
    margin: 0 auto; 
 
    position: relative; 
 
} 
 
/* headings */ 
 

 
header { 
 
    background-color: black; 
 
    width: 100%; 
 
    max-width: 640px; 
 
    position: relative; 
 
    /* z-index: -1 */ 
 
} 
 
header div { 
 
    border: 3px solid red; 
 
    color: white; 
 
    width: 70%; 
 
    margin: 0 auto 0.6em; 
 
} 
 
header p { 
 
    color: black; 
 
    background-color: white; 
 
    border: 3px solid black; 
 
    padding: 6px; 
 
} 
 
header p.phone { 
 
    color: white; 
 
    background-color: black; 
 
    border: 3px solid red; 
 
    padding: 6px; 
 
    width: 50%; 
 
    margin: 0.4em auto; 
 
    clear: both; 
 
} 
 
.established { 
 
    width: 25%; 
 
    float: left; 
 
} 
 
.award { 
 
    width: 25%; 
 
    float: right; 
 
} 
 
.options { 
 
    width: 25%; 
 
    margin: 0 auto; 
 
} 
 
.pointright { 
 
    background-color: black; 
 
    color: red; 
 
    position: absolute; 
 
    top: 0.4em; 
 
    left: 0.4em; 
 
} 
 
.pointleft { 
 
    background-color: black; 
 
    color: red; 
 
    position: absolute; 
 
    top: 0.4em; 
 
    right: 0.4em; 
 
} 
 
/* main content */ 
 

 
article { 
 
    color: black; 
 
    background-color: white; 
 
    text-align: left; 
 
    width: 65%; 
 
    margin: 0 auto; 
 
    padding: 5em 1em 1em; 
 
} 
 
h3 { 
 
    color: red; 
 
    margin: 1em 0 0.4em; 
 
} 
 
.menu { 
 
    margin: 0 0 0.5em; 
 
} 
 
.myo { 
 
    margin-left: 1em; 
 
} 
 
.list { 
 
    margin: 0 0 0 2em; 
 
} 
 
/* footer section */ 
 

 
footer { 
 
    background-color: white; 
 
    color: black; 
 
    border: 3px solid black; 
 
    padding: 0.5em; 
 
}
<!DOCTYPE html> 
 
<html lang="en"> 
 

 
<head> 
 
    <title>Big J&rsquo;s Deep Dish Pizza</title> 
 
    <!-- 
 
     Big J's Deep Dish Pizza main web page 
 
     Filename: index.html 
 
     
 
     Author: Justus Self 
 
     Date:  2/10/2017 
 
     HTML5 and CSS3 Illustrated Unit D, Skills Review 
 
     --> 
 
    <meta charset="utf-8"> 
 
    <meta name="viewport" content="width=device-width"> 
 
    <script src="modernizr.custom.62074.js"></script> 
 
    <link rel="stylesheet" href="styles.css"> 
 
</head> 
 

 
<body> 
 
    <div class="container"> 
 
    <header> 
 
     <div> 
 
     <h1>Big J&rsquo;s Deep Dish Pizza</h1> 
 
     <p>Authentic Chicago-style pies</p> 
 
     </div> 
 
     <p class="established">Established 
 
     <br>1974</p> 
 
     <p class="award">Toronto Times &ldquo;Best Pizza Joint&rdquo;</p> 
 
     <p class="options">Eat in, carry out, or call for delivery</p> 
 
     <p class="phone">(416) 555-3337</p> 
 
     <p class="pointright">&#9755;</p> 
 
     <p class="pointleft">&#9754;</p> 
 
    </header> 
 
    <article> 
 
     <h2>Menu</h2> 
 
     <p class="menu">(prices small/medium/large)</p> 
 
     <h3>Starters</h3> 
 
     <p class="menu">Garlic bread sticks: $5.00</p> 
 
     <p class="menu">Buffalo wings: $6.50</p> 
 
     <p class="menu">House salad: $4.00</p> 
 
     <p class="menu">Caesar salad: $5.50</p> 
 
     <p class="menu">Greek salad: $6.00</p> 
 
     <h3>Deep Dish Pizza</h3> 
 
     <p class="menu">Chicago classic: $15/18/20</p> 
 
     <p class="menu">Meat lover&rsquo;s: $18/22/25</p> 
 
     <p class="menu">Greek: $16/19/22</p> 
 
     <p class="menu">Vegetarian: $15/18/20</p> 
 
     <p class="menu">Make your own (plain cheese): $12/15/18</p> 
 
     <p class="myo">meats: $3/4/5</p> 
 
     <p class="list">sausage, pepperoni, ham, Canadian bacon</p> 
 
     <p class="myo">other toppings: $2/3/4</p> 
 
     <p class="list">mushrooms, onions, green peppers, black olives, fresh tomatoes, extra cheese, garlic, anchovies, fresh spinach, pepperoncini</p> 
 
    </article> 
 
    <footer> 
 
     <p>150 St. Joseph St.</p> 
 
     <p>Toronto, ON M5S 2C3</p> 
 
     <p>(416) 555-3337</p> 
 
    </footer> 
 
    </div> 
 
</body> 
 

 
</html>

+0

這實際上正是我所需要的,非常感謝。你知道如何讓這個「選項」元素與「已建立」和「最佳披薩聯合」元素保持一致? –

+0

我可以,但通過CSS瀏覽,我會改變很多關於那裏有什麼,因爲它誠實地看起來是一個熱門的混亂。 – Jhecht

+1

是的。我有一種感覺,我把整個項目搞糟了。但是,好吧。感謝Jhecht的幫助。 –