-
垂直導航條的設置
利用無序列表<ul>,在每個<li>標簽中加入超鏈接<a>,<ul>的樣式設為 list-style:none;
<a>的樣式設為 display:none;? text-decoration:none;? ?還可以再加上 text-indent:20px; 或者 text-align:center;? 使文字居中
查看全部 -
如果要給水平菜單增加整體背景,需要對(寬高)進行CSS設置?
? ? 菜單<li>浮動后,<li>脫離文檔流,導致<ul>將失去高度和寬度;如果需要對<ul>進行整體背景設置,首先要給<ul>定義寬、高。
查看全部 -
float:left查看全部
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>導航菜單</title>
<style type="text/css">
* { margin: 0; padding: 0; font-size: 14px; }
a { color: #333; text-decoration: none }
ul { list-style: none; height: 30px; border-bottom: 5px solid #F60; margin-top: 20px; padding-left: 50px; }
ul li { float: left }
ul li a { display: block; height: 30px; text-align: center; line-height: 30px; width:120px; background: #efefef; margin-left: 1px; }
a.on, a:hover { background: #F60; color: #fff; }
</style>
<script>
window.onload=function(){
? ? var aA=document.getElementsByTagName('a');
for(var i=0; i<aA.length; i++){
aA[i].onmouseover=function(){
var This=this;
clearInterval(This.time);
This.time=setInterval(function(){
This.style.width=This.offsetWidth+8+"px";
if(This.offsetWidth>=160)
clearInterval(This.time);
},30)
}
aA[i].onmouseout=function(){
clearInterval(this.time);
var This=this;
this.time=setInterval(function(){
This.style.width=This.offsetWidth-8+"px";
if(This.offsetWidth<=120){
This.style.width='120px';
clearInterval(This.time);
}
},30)
}
}
}
</script>
</head>
<body>
<ul>
? ? <li><a class="on" href="#">首 頁</a></li>
? ? <li><a href="#">新聞快訊</a></li>
<li><a href="#">產品展示</a></li>
? ? <li><a href="#">售后服務</a></li>
? ? <li><a href="#">聯系我們</a></li>
</ul>
</body>
</html>
查看全部 -
配圖111
查看全部 -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>導航菜單</title>
<style type="text/css">
*{margin:0; padding:0; font-size:14px;}
a{color:#333;text-decoration:none}
ul{list-style:none; height:50px; border-bottom:5px solid #F60; padding-left:30px;}
ul li{float:left; margin-top:20px;}
a{display:block;height:30px;text-align:center; line-height:30px; width:120px; background-color:#ccc;}
a.on, a:hover{ color:#fff;background-color:#F60;height:40px; line-height:40px;margin-top:-10px;】}
</style>
</head>
<body>
<ul>
? ? <li><a class="on" href="#">首 頁</a></li>
? ? <li><a href="#">新聞快訊</a></li>
? ? <li><a href="#">產品展示</a></li>
? ? <li><a href="#">售后服務</a></li>
? ? <li><a href="#">聯系我們</a></li>
? </ul>
</body>
</html>
查看全部 -
<script>
window.onload=function(){
? ? var aLi=document.getElementsByTagName('li');
for(var i=0; i<aLi.length; i++){
aLi[i].onmouseover=function(){
? ? ? ? ? ? //鼠標經過一級菜單,二級菜單動畫下拉顯示出來
var oSubNav=this.getElementsByTagName('ul')[0];
if(oSubNav){
? ? var This=oSubNav;
? ? clearInterval(This.time);
? ? This.time=setInterval(function(){
? ? ? ? This.style.height=This.offsetHeight+16+"px";
? ? ? ? if(This.offsetHeight>=120)
? ? ? ? {
? ? ? ? ? ? clearInterval(This.time);
? ? ? ? }
? ? },30)
}}
? ? ? ? //鼠標離開菜單,二級菜單動畫收縮起來。
aLi[i].onmouseout=function(){
var osubNav=this.getElementsByTagName('ul')[0];
? ? ? ? ? ? if(osubNav){
? ? ? ? ? ? ? ? var This=osubNav;
? ? ? ? ? ? ? ? clearInterval(This.time);
? ? ? ? ? ? ? ? This.time=setInterval(function(){
? ? ? ? ? ? ? ? ? ? This.style.height=This.offsetHeight-16+"px";
? ? ? ? ? ? ? ? ? ? if(This.offsetHeight<=0){
? ? ? ? ? ? ? ? ? ? ? ? clearInterval(This.time)
? ? ? ? ? ? ? ? ? ? }},30)
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ??
}
}
</script>
查看全部 -
background-position: x y;x向右為正, y向下為正
查看全部 -
實例
選擇鼠標指針浮動在其上的元素,并設置其樣式:
a:hover {? background-color:yellow; }
查看全部 -
text-indent查看全部
-
background-position:0 -30px;
查看全部 -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>導航菜單</title>
<style type="text/css">
*{margin:0; padding:0; font-size:14px;}
ul{ list-style:none; width:100px}
a{color:#333;text-decoration:none}
.nav li a{?
? ? display:block;?
? ? text-indent:20px;
? ? height:30px; line-height:30px; width:100px; background-color:#efefef; margin-bottom:1px;}
.nav li a:hover{ background-color:#F60; color:#fff}
</style>
</head>
<body>
<ul class="nav">
? ? <li><a href="#">首 頁</a></li>
? ? <li><a href="#">新聞快訊</a></li>
? ? <li><a href="#">產品展示</a></li>
? ? <li><a href="#">售后服務</a></li>
? ? <li><a href="#">聯系我們</a></li>
? </ul>
</body>
</html>
查看全部 -
JavaScript中常用的方法,例如:
網頁可見區(qū)域寬: document.body.offsetWidth (包括邊線的寬)
網頁可見區(qū)域高: document.body.offsetHeight (包括邊線的高)
查看全部 -
window.onload=function(){
??? var aA=document.getElementsByTagName('a');
?? ?for(var i=0; i<aA.length; i++){
?? ??? ?aA[i].onmouseover=function(){
?? ??? ??? ?var This=this;
?? ??? ??? ?clearInterval(This.time);//清除計時器
?? ??? ??? ?This.time=setInterval(function(){
?? ??? ??? ??? ??? ?This.style.width=This.offsetWidth+8+"px";
?? ??? ??? ??? ?// ?? ?alert(This.offsetWidth)
?? ??? ??? ??? ??? ?if(This.offsetWidth>=160)
?? ??? ??? ??? ??? ?clearInterval(This.time);
?? ??? ??? ??? ?},30)
?? ??? ?}
?? ??? ?aA[i].onmouseout=function(){
?? ??? ??? ??? ?clearInterval(this.time);
?? ??? ??? ??? ?var This=this;
?? ??? ??? ??? ?this.time=setInterval(function(){
?? ??? ??? ??? ??? ?This.style.width=This.offsetWidth-8+"px";
?? ??? ??? ??? ??? ?if(This.offsetWidth<=120){
?? ??? ??? ??? ??? ??? ?This.style.width='120px';
?? ??? ??? ??? ??? ??? ?clearInterval(This.time);
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?},30)
?? ??? ?}
?? ?}
}查看全部 -
a:hover{margin-bottom:30px; color:#fff;background-position:0 -30px;}
background-position:0 -30px;
0代表的是水平方向沒有任何移動,-30代表的是垂直方向向下移動30px,如果是30px,沒有“-”,那就是向上移動30px了,這個背景圖片移動的參照物是圖片本身所在的塊
查看全部
舉報