2016-11-16 55 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