css菜单下拉菜单_创建CSS3下拉菜单#2

css菜单下拉菜单

Creating CSS3 dropdown menu #2
Creating CSS3 dropdown menu #2

CSS3 Dropdown Menu #2 tutorial. This is our second drop down menu. Today it is in the green palette. The menu will include a submenus that will slide when we hovering the parent elements. That menu will good for green palette templates. And of course – no any JS – only pure CSS. Since this menu is made using CSS3 – it renders perfect on Firefox, Chrome and Safari browsers (possible last Opera will support it too). And, as I read, transitions have been billed to be included in IE10.

CSS3下拉菜单#2教程。 这是我们的第二个下拉菜单。 今天,它在绿色调色板中。 菜单将包含一个子菜单,当我们将其悬停在父元素上时,它将滑动。 该菜单将适合绿色调色板模板。 当然,没有任何JS,只有纯CSS。 由于此菜单是使用CSS3制作的,因此可以在Firefox,Chrome和Safari浏览器上完美呈现(最后一个Opera也可能支持)。 而且,据我所读,过渡已被标榜要包含在IE10中。

Here are final result (what we will creating):

这是最终结果(我们将创建的结果):

css3 menu2

CSS3菜单2

Here are samples and downloadable package:

以下是示例和可下载的软件包:

现场演示

[sociallocker]

[社交储物柜]

打包下载

[/sociallocker]

[/ sociallocker]

Ok, download the example files and lets start coding !

好的,下载示例文件并开始编码!

步骤1. HTML (Step 1. HTML)

As usual, we start with the HTML. Here are html with our menu.

和往常一样,我们从HTML开始。 这是带有菜单的html。

index.html (index.html)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <link rel="stylesheet" href="css/style.css" type="text/css" media="all">
    <title>CSS3 drop down menu #2</title>
</head>
<body>
    <div class="example">
        <ul id="nav">
            <li><a href="https://www.script-tutorials.com/">Home</a></li>
            <li><a href="https://www.script-tutorials.com/">Tutorials</a>
                <div>
                    <ul>
                        <li><a href="https://www.script-tutorials.com/category/html-css/">HTML / CSS</a></li>
                        <li><a href="https://www.script-tutorials.com/category/jquery/">JS / jQuery</a></li>
                        <li><a href="https://www.script-tutorials.com/category/php/">PHP</a></li>
                        <li><a href="https://www.script-tutorials.com/category/mysql/">MySQL</a></li>
                        <li><a href="https://www.script-tutorials.com/category/xslt/">XSLT</a></li>
                        <li><a href="https://www.script-tutorials.com/category/ajax/">Ajax</a></li>
                    </ul>
                </div>
            </li>
            <li><a href="https://www.script-tutorials.com/category/resources/">Resources</a>
                <div>
                    <ul>
                        <li><a href="https://www.script-tutorials.com/category/php/">PHP</a></li>
                        <li><a href="https://www.script-tutorials.com/category/mysql/">MySQL</a></li>
                        <li><a href="https://www.script-tutorials.com/category/xslt/">XSLT</a></li>
                        <li><a href="https://www.script-tutorials.com/category/ajax/">Ajax</a></li>
                    </ul>
                </div>
            </li>
            <li><a href="https://www.script-tutorials.com/category/resources/">Other pages</a>
                <div>
                    <ul>
                        <li><a href="#">Page 1</a></li>
                        <li><a href="#">Page 2</a></li>
                        <li><a href="#">Page 3</a></li>
                        <li><a href="#">Page 4</a></li>
                        <li><a href="#">Page 5</a></li>
                    </ul>
                </div>
            </li>
            <li><a href="https://www.script-tutorials.com/about/">About</a></li>
            <li><a href="https://www.script-tutorials.com/xxxxxxxxxxx/">Go Back To The Tutorial</a></li>
            <li class="pad"></li>
        </ul>
    </div>
</body>
</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <link rel="stylesheet" href="css/style.css" type="text/css" media="all">
    <title>CSS3 drop down menu #2</title>
</head>
<body>
    <div class="example">
        <ul id="nav">
            <li><a href="https://www.script-tutorials.com/">Home</a></li>
            <li><a href="https://www.script-tutorials.com/">Tutorials</a>
                <div>
                    <ul>
                        <li><a href="https://www.script-tutorials.com/category/html-css/">HTML / CSS</a></li>
                        <li><a href="https://www.script-tutorials.com/category/jquery/">JS / jQuery</a></li>
                        <li><a href="https://www.script-tutorials.com/category/php/">PHP</a></li>
                        <li><a href="https://www.script-tutorials.com/category/mysql/">MySQL</a></li>
                        <li><a href="https://www.script-tutorials.com/category/xslt/">XSLT</a></li>
                        <li><a href="https://www.script-tutorials.com/category/ajax/">Ajax</a></li>
                    </ul>
                </div>
            </li>
            <li><a href="https://www.script-tutorials.com/category/resources/">Resources</a>
                <div>
                    <ul>
                        <li><a href="https://www.script-tutorials.com/category/php/">PHP</a></li>
                        <li><a href="https://www.script-tutorials.com/category/mysql/">MySQL</a></li>
                        <li><a href="https://www.script-tutorials.com/category/xslt/">XSLT</a></li>
                        <li><a href="https://www.script-tutorials.com/category/ajax/">Ajax</a></li>
                    </ul>
                </div>
            </li>
            <li><a href="https://www.script-tutorials.com/category/resources/">Other pages</a>
                <div>
                    <ul>
                        <li><a href="#">Page 1</a></li>
                        <li><a href="#">Page 2</a></li>
                        <li><a href="#">Page 3</a></li>
                        <li><a href="#">Page 4</a></li>
                        <li><a href="#">Page 5</a></li>
                    </ul>
                </div>
            </li>
            <li><a href="https://www.script-tutorials.com/about/">About</a></li>
            <li><a href="https://www.script-tutorials.com/xxxxxxxxxxx/">Go Back To The Tutorial</a></li>
            <li class="pad"></li>
        </ul>
    </div>
</body>
</html>

步骤2. CSS (Step 2. CSS)

Here are used CSS styles. First two selectors (you can skip it) belong to our demo page. All rest – belong to menu.

这是使用CSS样式。 前两个选择器(您可以跳过它)属于我们的演示页面。 所有其余的-属于菜单。

css / style.css (css/style.css)

/* demo page styles */
body {
    background:#eee;
    margin:0;
    padding:0;
}
.example {
    position:relative;
    background:#fff url(../images/background.jpg);
    width:670px;
    height:470px;
    border:1px #000 solid;
    margin:20px auto;
    padding:15px;
    border-radius:3px;
    -moz-border-radius:3px;
    -webkit-border-radius:3px;
}
/* main menu styles */
#nav,#nav ul {
	font-family:verdana;
	list-style:none;
	margin:0;
	padding:0;
	position:relative;
}
#nav {
	height:50px;
	left:0;
	overflow:hidden;
	top:0;
}
#nav li {
	float:left;
	position:relative;
	z-index:10;
}
#nav li a {
	background:url(../images/bg-menu.png) no-repeat center top;
	color:#fff;
	display:block;
	float:left;
	font-size:14px;
	height:51px;
	line-height:40px;
	padding:0 10px;
	position:relative;
	text-decoration:none;
	z-index:20;
}
#nav li:first-child a {
	background:url(../images/bg-menu.png) no-repeat left top;
	padding-left:35px;
}
#nav li ul li:first-child a {
	background-image:none;
	padding-left:10px;
}
#nav li.pad {
	background:url(../images/bg-menu.png) no-repeat right top;
	display:block;
	height:51px;
	width:35px;
}
#nav ul {
	background:#009900;
	height:auto;
	padding:10px 0;
	position:absolute;
	top:-115px;
	width:180px;
	z-index:1;
	border-radius:8px; /*some css3*/
	-moz-border-radius:8px;
	-webkit-border-radius:8px;
	transition:0.8s ease-in-out;
	box-shadow:2px 2px 3px rgba(0, 0, 0, 0.5);
	-moz-box-shadow:2px 2px 3px rgba(0, 0, 0, 0.5);
	-webkit-box-shadow:2px 2px 3px rgba(0, 0, 0, 0.5);
	-moz-transition:0.8s ease-in-out;
	-o-transition:0.8s ease-in-out;
	-webkit-transition:all 0.8s ease-in-out;
}
#nav ul li {
	width:180px;
}
#nav ul li a {
	background:transparent;
	height:20px;
	line-height:20px;
	width:160px;
}
#nav:hover {
	height:200px;
}
#nav li:hover ul {
	-moz-transform:translate(0,161px); /*some css3*/
	-o-transform:translate(0,161px);
	-webkit-transform:translate(0,161px);
	transform: translate(0,161px);
}
#nav a:hover,#nav li:hover > a {
	color:#99ff33;
}

/* demo page styles */
body {
    background:#eee;
    margin:0;
    padding:0;
}
.example {
    position:relative;
    background:#fff url(../images/background.jpg);
    width:670px;
    height:470px;
    border:1px #000 solid;
    margin:20px auto;
    padding:15px;
    border-radius:3px;
    -moz-border-radius:3px;
    -webkit-border-radius:3px;
}
/* main menu styles */
#nav,#nav ul {
	font-family:verdana;
	list-style:none;
	margin:0;
	padding:0;
	position:relative;
}
#nav {
	height:50px;
	left:0;
	overflow:hidden;
	top:0;
}
#nav li {
	float:left;
	position:relative;
	z-index:10;
}
#nav li a {
	background:url(../images/bg-menu.png) no-repeat center top;
	color:#fff;
	display:block;
	float:left;
	font-size:14px;
	height:51px;
	line-height:40px;
	padding:0 10px;
	position:relative;
	text-decoration:none;
	z-index:20;
}
#nav li:first-child a {
	background:url(../images/bg-menu.png) no-repeat left top;
	padding-left:35px;
}
#nav li ul li:first-child a {
	background-image:none;
	padding-left:10px;
}
#nav li.pad {
	background:url(../images/bg-menu.png) no-repeat right top;
	display:block;
	height:51px;
	width:35px;
}
#nav ul {
	background:#009900;
	height:auto;
	padding:10px 0;
	position:absolute;
	top:-115px;
	width:180px;
	z-index:1;
	border-radius:8px; /*some css3*/
	-moz-border-radius:8px;
	-webkit-border-radius:8px;
	transition:0.8s ease-in-out;
	box-shadow:2px 2px 3px rgba(0, 0, 0, 0.5);
	-moz-box-shadow:2px 2px 3px rgba(0, 0, 0, 0.5);
	-webkit-box-shadow:2px 2px 3px rgba(0, 0, 0, 0.5);
	-moz-transition:0.8s ease-in-out;
	-o-transition:0.8s ease-in-out;
	-webkit-transition:all 0.8s ease-in-out;
}
#nav ul li {
	width:180px;
}
#nav ul li a {
	background:transparent;
	height:20px;
	line-height:20px;
	width:160px;
}
#nav:hover {
	height:200px;
}
#nav li:hover ul {
	-moz-transform:translate(0,161px); /*some css3*/
	-o-transform:translate(0,161px);
	-webkit-transform:translate(0,161px);
	transform: translate(0,161px);
}
#nav a:hover,#nav li:hover > a {
	color:#99ff33;
}

步骤3.图片 (Step 3. Images)

Our menu using only single image to reach custom background with and fading effect. Second image – just some green background for our demo.

我们的菜单仅使用单个图像即可达到具有自定义背景和淡入淡出的效果。 第二张图片–只是我们演示的一些绿色背景。

background menu
后台菜单
page background
页面背景
现场演示

结论 (Conclusion)

Hope you enjoyed with this tutorial, don’t forget to tell thanks and leave a comment :) Good luck!

希望您喜欢本教程,不要忘了感谢并发表评论:)祝您好运!

翻译自: https://www.script-tutorials.com/creating-css3-dropdown-menu-2/

css菜单下拉菜单

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值