越来越多的开发者喜欢将单页面尤其像产品介绍页面设计成用一个简单的导航条关联的页面各个重要部分(节点)。本例中,一个页面由多个重要节点组成,在页面一侧会垂直展示多个简单的导航远点,滑上圆点会展示对应节点部分的名称,点击页面会滚动到对应的节点部分,而导航条位置固定不变。
查看演示 下载源码
当屏幕足够小时(如手机移动设备),会在屏幕右下角展示一个图标,触控图标,则会展开导航菜单,点击菜单页面会滚动到对应的节点,效果非常酷。
HTML
我们的导航条是一个无序列表ul,包含在nav.cd-vertical-nav内,通过连接a#section1关联到对应的节点。元素button.cd-nav-trigger是用来作为小屏幕设备上的用来触发菜单的按钮。section.cd-section就是用来对应导航节点的内容。
<nav class="cd-vertical-nav"> <ul> <li><a href="#section1" class="active"><span class="label">Intro</span></a></li> <li><a href="#section2"><span class="label">Events</span></a></li> <!-- additional navigation items here --> </ul></nav> <button class="cd-nav-trigger cd-image-replace">Open navigation<span aria-hidden="true"></span></button> <section id="section1" class="cd-section"> <div class="content-wrapper"> <h1 id="垂直固定导航">垂直固定导航</h1> <a href="#section2" class="cd-scroll-down cd-image-replace">scroll down</a> </div></section> <section id="section2" class="cd-section"> <div class="content-wrapper"> <!-- section content here --> </div></section>
CSS
HTML结构部署好后,我们要为页面添加必要的CSS样式。在非常小的屏幕下(视图宽度小于800px),我们将.cd-nav-trigger和
.cd-nav-trigger { display: block; position: fixed; z-index: 2; bottom: 30px; right: 5%;} .cd-vertical-nav { position: fixed; z-index: 1; right: 5%; bottom: 30px; transform: scale(0); transform-origin: right bottom; transition: transform 0.2s;}.cd-vertical-nav.open { transform: scale(1);}
那么在大的屏幕设备上,我们首先是要 Modernizr 来检测当前使用的设备是否支持触屏,在非触控屏上会有鼠标滑上的效果。我们将右侧的垂直导航条设置为固定的高度和宽度,并将其固定在页面右侧。默认右侧导航之显示几个圆点,当鼠标滑上圆点时,导航条会打开,可以选择导航菜单。
@media only screen and (min-width: 800px) { .cd-vertical-nav { right: 0; top: 0; height: 100vh; width: 90px; } .cd-vertical-nav::before { /* this is the navigation background */ content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.8); transform: translateX(100%); transition: transform 0.4s; } .no-touch .cd-vertical-nav:hover::before, .touch .cd-vertical-nav::before { transform: translateX(0); } .cd-vertical-nav .label { display: block; transform: translateX(100%); transition: transform 0.4s; } .no-touch .cd-vertical-nav:hover .label, .touch .cd-vertical-nav .label { transform: translateX(0); }}
为了创建圆点和图标,可以使用::after和::before来为a元素添加伪类。
@media only screen and (min-width: 800px) { .cd-vertical-nav a { position: relative; padding: 3em 0 0; margin: 1.4em auto; } .cd-vertical-nav a::before, .cd-vertical-nav a::after { /* used to create the filled circle and the background icon */ content: ''; position: absolute; left: 50%; transition: transform 0.4s 0s; } .cd-vertical-nav a::before { /* filled circle */ top: 0; height: 32px; width: 32px; border-radius: 50%; background: #eaf2e3; transform: translateX(-50%) scale(0.25); } .cd-vertical-nav a::after { /* icon */ top: 8px; height: 16px; width: 16px; background: url(../img/cd-nav-icons.svg) no-repeat; transform: translateX(-50%) scale(0); } .no-touch .cd-vertical-nav:hover a::before, .no-touch .cd-vertical-nav:hover a::after, .touch .cd-vertical-nav li:nth-of-type(n) a::before, .touch .cd-vertical-nav li:nth-of-type(n) a::after { transform: translateX(-50%) scale(1); }}
当然到这里效果已经实现了,但是要实现点击导航菜单时页面做平滑滚动效果则需要借助jQuery来实现滚动动画。本例在下载源码包里已经打包了包含的全部jQuery代码,请大家下载后查看,本文不再描述。

HTML的未来将朝着更加语义化、功能化和模块化的方向发展。1)语义化将使标签更明确地描述内容,提升SEO和无障碍访问。2)功能化将引入新元素和属性,满足用户需求。3)模块化将支持组件化开发,提高代码复用性。

htmlattributesarecrucialinwebdevelopment forcontrollingBehavior,外观和功能

alt属性是HTML中标签的重要部分,用于提供图片的替代文本。1.当图片无法加载时,alt属性中的文本会显示,提升用户体验。2.屏幕阅读器使用alt属性帮助视障用户理解图片内容。3.搜索引擎索引alt属性中的文本,提高网页的SEO排名。

HTML、CSS和JavaScript在网页开发中的作用分别是:1.HTML用于构建网页结构;2.CSS用于美化网页外观;3.JavaScript用于实现动态交互。通过标签、样式和脚本,这三者共同构筑了现代网页的核心功能。

设置标签的lang属性是优化网页可访问性和SEO的关键步骤。1)在标签中设置lang属性,如。2)在多语言内容中,为不同语言部分设置lang属性,如。3)使用符合ISO639-1标准的语言代码,如"en"、"fr"、"zh"等。正确设置lang属性可以提高网页的可访问性和搜索引擎排名。

htmlattributeseresene forenhancingwebelements'functionalityandAppearance.TheyAdDinformationTodeFineBehavior,外观和互动,使网站互动,响应式,visalalyAppealing.AttributesLikutesLikeSlikEslikesrc,href,href,href,类,类型,类型,和dissabledtransfransformformformformformformformformformformformformformformforment

toCreateAlistinHtml,useforforunordedlistsandfororderedlists:1)forunorderedlists,wrapitemsinanduseforeachItem,RenderingeringAsabulleTedList.2)fororderedlists,useandfornumberedlists,useandfornumberedlists,casundfornumberedlists,customeizableWithTheTtheTthetTheTeTeptTributeFordTributeForderForderForderFerentNumberingSnumberingStyls。

HTML用于构建结构清晰的网站。1)使用标签如、、定义网站结构。2)示例展示了博客和电商网站的结构。3)避免常见错误如标签嵌套不正确。4)优化性能通过减少HTTP请求和使用语义化标签。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

Dreamweaver Mac版
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。