2016-11-16 63 views
0

如何獲得如何確保頁眉浮動與水平頁面擴展?

新聞

拓展水平與頁面,而不是停留剩下什麼?

<!doctype html> <html> <head> <title>Technology - BBC News</title> <style type="text/css"> #topbar { 
 
    width: 1050px; 
 
    margin: 0 auto; 
 
    height: 40px; 
 
} 
 
body { 
 
    margin: 0; 
 
    padding: 0; 
 
    font-family: Helvetica, Arial, sans-serif; 
 
} 
 
#logo { 
 
    margin-top: 8px; 
 
    width: 100px; 
 
    float: left; 
 
    margin-right: 8px; 
 
} 
 
.topbar-section { 
 
    float: left; 
 
    border-left: 1px #CCCCCC solid; 
 
    height: 100%; 
 
} 
 
#signin-image { 
 
    width: 25px; 
 
    margin: 11px 15px; 
 
    float: left; 
 
} 
 
#signin-text { 
 
    font-weight: bold; 
 
    font-size: 90%; 
 
    position: relative; 
 
    top: 14px; 
 
    padding-right: 50px; 
 
} 
 
#wigglyline { 
 
    float: left; 
 
    height: 40px; 
 
} 
 
#bell { 
 
    height: 25px; 
 
    margin: 9px 8px 0 8px; 
 
} 
 
#bell-div { 
 
    float: left; 
 
} 
 
.topbar-menu { 
 
    font-weight: bold; 
 
    font-size: 90%; 
 
    padding: 13px 15px 0 15px; 
 
    height: 27px; 
 
} 
 
#more-arrow { 
 
    width: 16px; 
 
    margin-left: 20px; 
 
} 
 
#searchbox { 
 
    background-color: #d3d3d3; 
 
    border; 
 
    none; 
 
    font-weight: bold; 
 
    font-size: 12px; 
 
    padding: 5px; 
 
    margin: -4px 0 5px; 
 
    float: left; 
 
} 
 
#magnifying-glass { 
 
    height: 27px; 
 
    margin-top: -4px; 
 
} 
 
.clear { 
 
    clear: both; 
 
} 
 
#menu-bar-container { 
 
    background-color: #9e2c25; 
 
    width: 100%; 
 
    height: 70px; 
 
    margin: 0 auto; 
 
} 
 
#menubar { 
 
    width: 1050px; 
 
    margin: 0 auto; 
 
} 
 
h1 { 
 
    padding: 10px; 
 
    margin: 0 auto; 
 
    color: white; 
 
    font-size: 40px; 
 
    font-weight: normal; 
 
    text-align: justify; 
 
    text-align-last: justify 
 
} 
 
</style> </head>
<body> 
 

 
    <div id="topbar"> 
 

 
    <img id="logo" src="C:\Users\Kaitlyn\Desktop\Complete Web Developer Course\images\bbc-logo.png"></img> 
 

 
    <div id="signin-div" class="topbar-section"> 
 

 
     <img id="signin-image" src="C:\Users\Kaitlyn\Desktop\Complete Web Developer Course\images\signinimage.png"></img> 
 

 
     <span id="signin-text">Sign in</span> 
 

 
    </div> 
 

 
    <div id="bell-div"> 
 

 
     <img id="wigglyline" src="C:\Users\Kaitlyn\Desktop\Complete Web Developer Course\images\squiggle.png"> 
 

 
     <img id="bell" src="C:\Users\Kaitlyn\Desktop\Complete Web Developer Course\images\bell.png"> 
 

 
    </div> 
 

 
    <div class="topbar-section topbar-menu"> 
 

 
     News 
 

 
    </div> 
 

 
    <div class="topbar-section topbar-menu"> 
 

 
     Sports 
 

 
    </div> 
 

 
    <div class="topbar-section topbar-menu"> 
 

 
     Weather 
 

 
    </div> 
 

 
    <div class="topbar-section topbar-menu"> 
 

 
     iPlayer 
 

 
    </div> 
 

 
    <div class="topbar-section topbar-menu"> 
 

 
     TV 
 

 
    </div> 
 

 

 
    <div class="topbar-section topbar-menu"> 
 

 
     More 
 

 
     <img id="more-arrow" src="C:\Users\Kaitlyn\Desktop\Complete Web Developer Course\images\downarrow.png"> 
 

 
    </div> 
 

 
    <div class="topbar-section topbar-menu"> 
 

 
     <input id="searchbox" type="text" value="Search"> 
 

 
     <input type="image" id="magnifying-glass" src="C:\Users\Kaitlyn\Desktop\Complete Web Developer Course\images\magnifying-glass.png"> 
 

 
    </div> 
 
    </div> 
 

 

 
    <div class="clear"></div> 
 

 
    <div id="menu-bar-container"> 
 

 

 
    <div id="menu-bar"> 
 

 
     <h1>News</h1> 
 

 

 
    </div> 
 

 

 

 

 

 
    </div> 
 

 

 

 

 

 

 

 

 

 
</body> 
 

 
</html>

我重視並更新了搜索欄是包含紅色背景和新聞標題中的div以上。在水平擴展瀏覽器頁面的同時,您應該能夠看到搜索欄如何反應並繼續隨頁面一起流動,而新聞標題保留在頁面的左側。

如果我需要關閉div不同或改變定位,請讓我知道。

基本上我試圖讓網站這樣操作:請按照鏈接http://www.completewebdevelopercourse.com/content/2-css/bbc.html

+1

你希望它是在頁面的中心? – repzero

+0

你想讓新聞中心對齊嗎? –

+0

在我正在處理的頁面中,有一個搜索欄,其中包含當頁面在新聞標題的紅色欄正上方擴展時水平展開的選項卡。我遇到的問題是試圖讓「新聞」在紅色的div中水平擴展,但是當新聞被擴大時,「新聞」會停留在左邊框上方,而「新聞」上方的搜索欄會展開。 @NiyokoYuliawan – Siemens

回答

0

你忘記了在你的CSS破折號(-)。它應該#menu-bar而不是#menubar

#topbar { 
 
    width: 1050px; 
 
    margin: 0 auto; 
 
    height: 40px; 
 
} 
 
body { 
 
    margin: 0; 
 
    padding: 0; 
 
    font-family: Helvetica, Arial, sans-serif; 
 
} 
 
#logo { 
 
    margin-top: 8px; 
 
    width: 100px; 
 
    float: left; 
 
    margin-right: 8px; 
 
} 
 
.topbar-section { 
 
    float: left; 
 
    border-left: 1px #CCCCCC solid; 
 
    height: 100%; 
 
} 
 
#signin-image { 
 
    width: 25px; 
 
    margin: 11px 15px; 
 
    float: left; 
 
} 
 
#signin-text { 
 
    font-weight: bold; 
 
    font-size: 90%; 
 
    position: relative; 
 
    top: 14px; 
 
    padding-right: 50px; 
 
} 
 
#wigglyline { 
 
    float: left; 
 
    height: 40px; 
 
} 
 
#bell { 
 
    height: 25px; 
 
    margin: 9px 8px 0 8px; 
 
} 
 
#bell-div { 
 
    float: left; 
 
} 
 
.topbar-menu { 
 
    font-weight: bold; 
 
    font-size: 90%; 
 
    padding: 13px 15px 0 15px; 
 
    height: 27px; 
 
} 
 
#more-arrow { 
 
    width: 16px; 
 
    margin-left: 20px; 
 
} 
 
#searchbox { 
 
    background-color: #d3d3d3; 
 
    border; 
 
    none; 
 
    font-weight: bold; 
 
    font-size: 12px; 
 
    padding: 5px; 
 
    margin: -4px 0 5px; 
 
    float: left; 
 
} 
 
#magnifying-glass { 
 
    height: 27px; 
 
    margin-top: -4px; 
 
} 
 
.clear { 
 
    clear: both; 
 
} 
 
#menu-bar-container { 
 
    background-color: #9e2c25; 
 
    width: 100%; 
 
    height: 70px; 
 
    margin: 0 auto; 
 
} 
 
#menu-bar { /* Change this line! */ 
 
    width: 1050px; 
 
    margin: 0 auto; 
 
} 
 
h1 { 
 
    padding: 10px; 
 
    margin: 0 auto; 
 
    color: white; 
 
    font-size: 40px; 
 
    font-weight: normal; 
 
    text-align: justify; 
 
    text-align-last: justify 
 
}
<div id="topbar"> 
 

 
    <img id="logo" src="http://www.completewebdevelopercourse.com/content/2-css/images/bbc-logo.png"> 
 

 
    <div id="signin-div" class="topbar-section"> 
 

 
    <img id="signin-image" src="http://www.completewebdevelopercourse.com/content/2-css/images/signinimage.png"> 
 
    <span id="signin-text">Sign in</span> 
 
    </div> 
 
    <div id="bell-div"> 
 
    <img id="wigglyline" src="http://www.completewebdevelopercourse.com/content/2-css/images/wigglyline.png"> 
 
    <img id="bell" src="http://www.completewebdevelopercourse.com/content/2-css/images/bell.png"> 
 
    </div> 
 
    <div class="topbar-section topbar-menu"> 
 

 
    News 
 

 
    </div> 
 

 
    <div class="topbar-section topbar-menu"> 
 

 
    Sports 
 

 
    </div> 
 

 
    <div class="topbar-section topbar-menu"> 
 

 
    Weather 
 

 
    </div> 
 

 
    <div class="topbar-section topbar-menu"> 
 

 
    iPlayer 
 

 
    </div> 
 

 
    <div class="topbar-section topbar-menu"> 
 

 
    TV 
 

 
    </div> 
 

 

 
    <div class="topbar-section topbar-menu"> 
 

 
    More 
 

 
    <img id="more-arrow" src="C:\Users\Kaitlyn\Desktop\Complete Web Developer Course\images\downarrow.png"> 
 

 
    </div> 
 

 
    <div class="topbar-section topbar-menu"> 
 

 
    <input id="searchbox" type="text" value="Search"> 
 

 
    <input type="image" id="magnifying-glass" src="C:\Users\Kaitlyn\Desktop\Complete Web Developer Course\images\magnifying-glass.png"> 
 

 
    </div> 
 
</div> 
 

 

 
<div class="clear"></div> 
 

 
<div id="menu-bar-container"> 
 

 

 
    <div id="menu-bar"> 
 

 
    <h1>News</h1> 
 

 

 
    </div> 
 

 

 

 

 

 
</div>

+0

我已經添加了更多的代碼到原始問題,這可能會更有意義。 \t \t 我附加並更新了包含紅色背景和新聞標題的div上方的搜索欄。在水平擴展瀏覽器頁面的同時,您應該能夠看到搜索欄如何反應並繼續隨頁面一起流動,而新聞標題保留在頁面的左側。 – Siemens

+0

@Siemens您所描述的代碼示例沒有紅色背景。請使用代碼片段功能來確保您複製了正確的代碼。 –

+0

我已經更新了代碼片段中的所有內容 - – Siemens