win10开始菜单CSS源代码,DIV源代码,

html-css06

win10开始菜单CSS源代码,DIV源代码,,第1张

该下拉菜单的HTML结构非常简单,基本的HTML结构如下:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

<div id="top-bar" class="top-bar">

<div class="bar">

<button id="navbox-trigger" class="navbox-trigger"><i class="fa fa-lg fa-th"></i></button>

</div>

<div class="navbox">

<div class="navbox-tiles">

<a href="#" class="tile">

<div class="icon"><i class="fa fa-home"></i></div><span class="title">Home</span>

</a>

......

</div>

</div>

</div>

CSS样式

在CSS样式中,顶部导航条.top-bar设置为固定高度50像素和相对定位,并给出一个较高的z-index值。

?

1

2

3

4

5

.top-bar {

height: 50px

position: relative

z-index: 1000

}

下拉菜单.navbox开始的时候是隐藏的,它采用绝对定位,通过translateY方法将它移动到导航条上方200像素的地方。

?

1

2

3

4

5

6

7

8

9

10

11

12

13

.top-bar .navbox {

visibility: hidden

opacity: 0

position: absolute

top: 100%

left: 0

z-index: 1

-webkit-transform: translateY(-200px)

-ms-transform: translateY(-200px)

transform: translateY(-200px)

-webkit-transition: all .2s

transition: all .2s

}

接着在下拉菜单被激活的时候,它的透明度被设置回1,变为可见状态,并通过translateY方法将它移动回原来的位置。

?

1

2

3

4

5

6

7

8

9

.top-bar.navbox-open .navbox {

visibility: visible

opacity: 1

-webkit-transform: translateY(0)

-ms-transform: translateY(0)

transform: translateY(0)

-webkit-transition: opacity .3s, -webkit-transform .3s

transition: opacity .3s, transform .3s

}

JavaScript

该特效中使用jQUery切换相应的class类和用于打开菜单按钮。

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

(function () {

$(document).ready(function () {

$('#navbox-trigger').click(function () {

return $('#top-bar').toggleClass('navbox-open')

})

return $(document).on('click', function (e) {

var $target

$target = $(e.target)

if (!$target.closest('.navbox').length &&!$target.closest('#navbox-trigger').length) {

return $('#top-bar').removeClass('navbox-open')

}

})

})

}.call(this))

为什么不要js的呢?用js不是很简单吗,又不会产生那么多需要兼容的问题。jquery水平二级导航栏实例a{text-decoration: noneoutline: nonecursor:pointercolor:white}ul{ list-style: none}ul li{float: leftmargin: 0padding:7px 7px 0px 7pxborder-right:1px dotted whiteheight:25pxbackground:tomatofont-size:14pxcolor:whitetext-align:center}li a{display: block}ul li span{display:noneposition: absolutez-index: 1000background: redcolor: #fffmargin-top:10pxpadding: 5px/**设置子栏绝对定位*/width:auto_width:100px/**IE6下无法通过设置为auto来自适应子栏的宽度,所以做了一个折中的设置*/-moz-border-radius-bottomright: 5px/**为子栏增加圆角样式,只能在Chrome和FF下显示良好,IE下无效*/-khtml-border-radius-bottomright: 5px-webkit-border-bottom-right-radius: 5px-moz-border-radius-bottomleft: 5px-khtml-border-radius-bottomleft: 5px-webkit-border-bottom-left-radius: 5px}ul li span a{color:whitedisplay:inline}/**使子栏水平显示*/ul li span a:hover{color:tomatobackground:white}首页项目一 1.1 1.2 1.3 项目二 2.1 2.2 2.3 项目三 3.1 3.2 3.3 帮助$("ul li").hover(function() {$(this).css({ 'background' : 'red'})$(this).find("span").show()//显示子栏} , function() { $(this).css({ 'background' : 'tomato'})$(this).find("span").hide()//隐藏子栏})效果图如下: