带有徽标和导航的 HTML5/CSS 粘性标题 [英] HTML5/CSS Sticky Header with logo and navigation
问题描述
我想创建一个主页,您首先会在其中看到一个图像,而实际导航栏位于浏览器底部.当您向下滚动时,导航应在到达浏览器顶部时停留在顶部.
屏幕左侧有 1 个徽标,右侧有导航.导航应该有一个背景作为跨屏幕的栏,并且徽标应该与此重叠.当我向下滚动时,我首先希望徽标(例如 250 像素高)贴在顶部,然后当我进一步向下滚动时,我希望导航 + 背景(约 100 像素)也贴在顶部.我也不知道为什么会产生空白.在第一张和第二张图片之间应该只有大约 100px(灰色条(导航栏)的高度.使用此代码,除了背景栏之外的所有内容都可以工作..
@charset "utf-8";*{边距:0px 0px 0px 0px;填充:0px 0px 0px 0px;}.top-容器{位置:绝对;宽度:100%;}.stopleft{填充顶部:34%;宽度:50%;边距:0px 0px 0px 0px;边框:实心 0px #000;向左飘浮;}.stopright{填充顶部:44.2%;宽度:50%;边距:0px 0px 0px 0px;边框:实心 0px #000;浮动:对;}.whiteBarSmall{宽度:100%;填充顶部:5%;背景颜色:#fff;位置:绝对;}.商标{位置:粘性;顶部:0;宽度:50%;向左飘浮;}.导航{边距:0px 0px 0px 0px;边框:实心 0px #000;位置:粘性;顶部:0;宽度:50%;浮动:对;}.navigation ul{高度:100px;}.按钮{列表样式:无;边距:25px 20px 25px 20px;浮动:对;}.navBackground{边框:实心 0px #000;位置:粘性;顶部:0;宽度:100%;填充顶部:5%;背景颜色:#a7a7a7;浮动:对;z-索引:-1;}.whiteBarLarge{宽度:100%;填充顶部:10%;背景色:#fff;}.indexImage{宽度:100%;}.sticky {位置:固定;顶部:0;宽度:100%;}.sticky + .content {填充顶部:102px;}页脚{宽度:100%;填充顶部:2.5%;背景颜色:#a7a7a7;}.navigation a:link {颜色:#000;显示:块;文本对齐:居中;文字装饰:无;字体系列:'Volkhov',无衬线;字体大小:30px;}.navigation a:visited {颜色:#000;显示:块;文本对齐:居中;文字装饰:无;字体系列:'Volkhov',无衬线;字体大小:30px;}.navigation a:focus {颜色:#000;显示:块;文本对齐:居中;文字装饰:无;字体系列:'Volkhov',无衬线;字体大小:30px;}.navigation a:hover {颜色:#000;显示:块;文本对齐:居中;文字装饰:无;字体系列:'Volkhov',无衬线;字体大小:30px;}.navigation a:active {颜色:#000;显示:块;文本对齐:居中;文字装饰:无;字体系列:'Volkhov',无衬线;字体大小:30px;}
<html lang="de"><头><meta charset="utf-8"/><title>测试</title><meta name="description" content="...."/><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"><link rel="icon" href="pics/favicon.ico"/><link rel="stylesheet" href="styles/basics.css" type="text/css"/><link rel="stylesheet" href="styles/index.css" type="text/css"/><link rel="stylesheet" href="styles/links.css" type="text/css"/><link href="https://fonts.googleapis.com/css?family=Volkhov" rel="stylesheet">头部><身体><div class="top-container"><img src="https://pre00.deviantart.net/e893/th/pre/i/2006/132/b/4/widescreen_dreamy_world_6th_by_grafixeye.jpg" alt="测试标题" width="100%"/>
<div class="stopleft"></div><div class="stopright"></div><div class="logo"><img src="https://png.icons8.com/ios/1600/external-link-squared-filled.png" alt="Logo" width="50%"/></div><div class="导航"><ul><li class="button"><a href="pages/uber_uns.html">Über uns</a></li><li class="button"><a href="pages/kontakt.html">Kontakt</a></li><li class="button"><a href="pages/preise.html">Preise</a></li><li class="button"><a href="pages/blog.html">博客</a></li><li class="button"><a href="pages/galerie.html">Galerie</a></li>
<div class="navBackground"></div><div class="indexImage"><img src="http://www.hdwallpapery.com/static/images/dual-monitor-wallpapers-hd_dJyDicr.jpg" alt="" width="100%"/>
<div class="whiteBarLarge">
<div class="indexImage"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRUPqqyzvnT6JVdDUeUgzDvX9tUpwjKv59spOBgVdYtf-2EaLhD" alt=""width="100%"/>
<div class="whiteBarLarge"></div><页脚></页脚>