分享
 
 
 

实用:JS实现鼠标悬停显示不同的页面

王朝html/css/js·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

当鼠标按顺序悬停在菜单上时,可在同一位置显示不同的页面

作者:Stu Nicholls 

翻译:forestgan

信息

这是 cssplay的站长根据其最近创作的dropdown and flyout menus而改编而成的,当鼠标按顺序悬停在菜单上时,可在同一位置显示不同的页面,可在Opera, IE5.5, IE6, IE7 beta,Safari 1.3.2 & Firefox.中正确显示和工作,不兼容Mac IE5。

鼠标悬停在菜单和页面上时显示文字与图片以及链接,滚动条要加在每个页上。

样式

对于非IE浏览器来说是比较简单的,只用一个样式表。

<link rel="stylesheet" media="all" type="text/css" href="one_page.css" />

/* common styling */

/* set up the overall width of the menu div, the font and the margins with a relative position*/

.menu {

font-family: verdana, arial, sans-serif;

width:750px;

margin:0;

position:relative;

}

/* remove the bullets and set the margin and padding to zero for the unordered list */

.menu ul {

padding:0;

margin:0;

list-style-type: none;

border:0;

}

/* float the list so that the items are in a line */

.menu ul li {

float:left;

}

/* style the links to be 249px wide by 30px high with a top and right border 1px solid white. Set the background color and the font size. */

.menu ul li a, .menu ul li a:visited {

display:block;

text-align:center;

text-decoration:none;

width:249px;

height:30px;

color:#000;

border:1px solid #fff;

border-width:1px 1px 0 0;

background:#c9c9a7;

line-height:30px;

font-size:11px;

}

/* make the dropdown ul invisible */

.menu ul li ul {

display: none;

}

/* specific to non IE browsers */

/* set the background and foreground color of the main menu li on hover */

.menu ul li:hover a {

color:#fff;

background:#b3ab79;

}

/* make the sub menu ul visible and position it beneath the first list item */

.menu ul li:hover ul {

text-align:left;

display:block;

position:absolute;

top:30px;

left:0;

text-align:left;

}

/* make the sub menu ul li the full width with padding and border. Add an auto scroll bar */

.menu ul li:hover ul li {

background:#eee;

color:#000;

padding:10px;

width:689px;

height:180px;

overflow:auto;

border:20px solid #b3ab79;

}

/*float the image left with padding and no border */

.menu ul li:hover ul li img {

float:left;

padding:10px 10px 10px 0;

border:0;

}

/* style the paragraph font height */

.menu ul li:hover ul li p {

font-size:0.9em;

}

/* style the background and foreground color of the submenu links */

.menu ul li:hover ul li a {

display:inline;

background:#eee;

color:#c00;

text-decoration:underline;

border:0;

}

/* style the background and forground colors of the links on hover */

.menu ul li:hover ul li a:hover {

text-decoration:none;

color:#000;

}

而IE还需要专门为它加一个,用条件判断加入。

<!--[if lte IE 6]>

<link rel="stylesheet" media="all" type="text/css" href="one_page_ie.css" />

<![endif]-->

/* styling specific to Internet Explorer IE5.5 and IE6. Yet to see if IE7 handles li:hover */

/* Get rid of any default table style */

table {

border-collapse:collapse;

margin:0;

padding:0;

}

/* ignore the link used by 'other browsers' */

.menu ul li a.hide, .menu ul li a:visited.hide {

display:none;

}

/* set the background and foreground color of the main menu link on hover */

.menu ul li a:hover {

color:#fff;

background:#b3ab79;

}

/* make the sub menu ul visible and position it beneath the first list item */

.menu ul li a:hover ul {

text-align:left;

display:block;

position:absolute;

top:31px;

left:0;

}

/* make the sub menu ul li the full width with padding and border. Add an auto scroll bar */

.menu ul li a:hover ul li {

background:#eee;

color:#000;

padding:10px;

width:746px;

height:240px;

overflow:auto;

border:20px solid #b3ab79;

w\idth:689px;

he\ight:180px;

}

/*float the image left with padding and no border */

.menu ul li a:hover li img {

float:left;

padding:10px 10px 10px 0;

border:0;

}

/* style the paragraph font height */

.menu ul li a:hover p {

font-size:0.7em;

f\ont-size:1em;

}

/* style the background and foreground color of the submenu links */

.menu ul li a:hover ul li a {

display:inline;

width:1px;

word-wrap:normal;

background:#eee;

color:#c00;

text-decoration:underline;

border:0;

}

/* style the background and forground colors of the links on hover */

.menu ul li a:hover ul li a:hover {

text-decoration:none;

color:#000;

}

xhtml

你会看到用条件判断来给 IE添加表格,. 其他浏览器不会用到表格,而将正常使用无序列表。文档类型声明是必须要加的,反之不能正常工作。

运行代码框

<!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>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<title> stu nicholls | CSS PLaY | cross browser tabbed pages with embeded links</title>

<meta name="Author" content="Stu Nicholls"/>

<meta name="Keywords" content="cssplay, css play, Cascading, Style, Sheets, CSS1, CSS2, CSS, XHTML1.1, w3c, doing it with style, recommendations, opacity, box model, mozilla, opera, netscape, internet explorer, v6, v7.23, techniques, layout, three column, cutting edge, experimental, validation, validate, navigation, pop-up, pull-down, menus, tips, tricks, css mouseover, mouseovers, CSS experiments, CSS demonstrations"/>

<meta name="Description" content="CSS ~ Cutting edge Cascading Style Sheets. Experiments in CSS"/>

<link rel="stylesheet" media="all" type="text/css" href="http://www.forest53.com/tutorials/onepage/one_page.css"/>

<style type="text/css">

body {text-align:center; font-family:verdana, arial, sans-serif; font-size:76%; color:#000; background:#fff url(back.gif) repeat-x; padding:0; border:0; margin:0;}

</style>

<!--[if lte IE 6]>

<link rel="stylesheet" media="all" type="text/css" href="http://www.forest53.com/tutorials/onepage/one_page_ie.css" />

<![endif]-->

<!--[if lte IE 6]>

<style>

#ads {display:none;}

#smallads {display:none;}

#adsie {clear:both; text-align:center; width:750px; margin-top:10px;}

#smalladsie {clear:both; text-align:center; width:468px; margin-top:10px;}

</style>

<![endif]-->

</head>

<body>

<div class="menu" style="margin: 10px auto;">

<ul>

<li><a class="hide" href="#nogo">John Constable</a>

<!--[if lte IE 6]>

<a href="../menu/index.html">John Constable

<table><tr><td>

<![endif]-->

<ul>

<li>

<p>Although he showed an early talent for art and began painting his native Suffolk scenery before he left school, his great originality matured slowly.</p>

<img src="constable.jpg" alt="The Hay Wain" title="The Hay Wain"/>

<p>He committed himself to a career as an artist only in 1799, when he joined the Royal Academy Schools and it was not until 1829 that he was grudgingly made a full Academician, elected by a majority of only one vote.</p>

<p>In 1816 he became financially secure on the death of his father and married Maria Bicknell after a seven-year courtship and in the fact of strong opposition from her family. During the 1820s he began to w

[1] [2] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有