Whatever:hover 3.11
Most modern browsers support the :hover selector for any html element. This is cool, because it enables you to, for instance, apply a mouseover effect to table rows <tr> using only CSS. IE however, has an erratic support for :hover at best, depending on the particular version your visitor is using.
Whatever:hover is a small script that automatically patches :hover, :active and :focus for IE6, IE7 and IE8 quirks, letting you use them like you would in any other browser. Version 3 introduces ajax support, meaning that any html that gets inserted into the document via javascript will also trigger :hover, :active and :focus styles in IE.
If you're already familiar with whatever:hover and just want to download it, scroll down and grab the latest version. For some in depth stuff on the other hand, just continue reading.
Getting it to work How do I use it?
Link whatever:hover to the body element, and you're all set. Note that behavior URLs are relative to the html file, not to the CSS file like a background image URL would be.
body {
behavior: url("csshover3.htc");
}
IE only behaviours How does it work?
All browsers provide some way to look at a stylesheet's rules using javascript, and dynamically insert new rules. Normally, IE returns "unknown" for anything it does not support, for instance; a "div p:first-child" would change into "div p:unknown", and a "p a[href]" would be returned as "UNKNOWN" altogether. Fortunately IE recognizes :hover as something it's familiar with, and leaves it alone.
IE also supports so called behaviors; both predefined functionality like dynamic content loading or persistent data storage, as well as custom behaviors that you can build into an .htc or .hta file. These behaviors are linked to html nodes via css, and "enhance" the nodes that are selected by a rule's selector with the given behavior.
Combining the above, it should be possible to create a bahavior that searches the styles for rules IE doens't support, and trick affected elements into applying the associated styles some other way. The steps involved in this are something like:
Search all stylesheets for :hover rules IE doesn't support,
Insert a new rule IE does support, like one with class names,
and finally, set up script events for switching class names.
This way, :hover, :active and :focus can be supported, and as a developer you don't have to do anything except including the behavior. Everything else runs on full automatic.
Unlike versions 1 and 2, version 3 also supports dynamically added html (ajax). The difference is that 1 and 2 actively searched for affected elements onload of the page (so; only once), whereas 3 uses expressions to let nodes do a callback themselves. Read the commented version for more details on this.
for a menu An example of :hover
A common use for :hover is creating menusystems using lists. A dual level menusystem is almost too easy to create using this behavior. For instance, if you would remove the javascript from the suckerfish dropdown, described in the A list apart article and add this behavior to the body, it will work.
Multiple level menus require a different approach though. This is because IE lacks support for the > child selector, which would be perfect to show direct submenus, and not yet the deeper nested ones:
li:hover > ul {
/* no go in IE */
}
There is an alternative way to simulate this, using simple descendant selectors only. A previously described method was based on the use of extra classnames, but an easier way is to use the specificity of CSS. Every CSS rule has a certain importance, which can be determined by simply counting the different elements of a rule. Nodenames count as "1", class, pseuo-class and attribute selectors count as "10", and ids as "100". Take the example below.
ul ul {
display:none;
}
li:hover ul {
display:block;
}
The reason that this works, is because of the specificity. The first rule contains only 2 nodenames, which makes its value 2. The second also contains 2 nodenames, but the :hover pseudo class is worth 10, so the combined value of the rule is 12. Because 12 exceeds 2, a hover on the li will show the ul (or rather all of them) nested within.
So how does this help getting around the > child selector? Well, if a rule of 12 would show all submenu's, all we would have to do is make a rule that is worth more than 12 to hide the next menus. Subsequently, that menu would have to be shown by another rule, again worth even more, and so on. For 3 levels of navigation, the CSS code is surprisingly short:
/* 2 and 13 */
ul ul, li:hover ul ul {
display:none;
}
/* 12 and 23*/
li:hover ul, li:hover li:hover ul {
display:block;
}
This way (and adding more for 4 or more levels) unlimited nesting of menu's can be used, without ever needing extra classnames.
script events mayhem Optimizing
There is just one more thing to consider. The .htc file searches the stylesheet for :hover rules, and attaches a mouseover and mouseout event to elements that in its opinion require a scripted hover effect to work as the css file says. To find those elements, everything after (and including) the :hover is trimmed from the selector, and the resulting elements are selected and processed. A rule like:
#menu li:hover ul {
...
}
... would be trimmed back to this to find all the elements that might need hover events:
#menu li {
...
}
Obviously this would select every single <li> element in the entire menu, attaching events to heaps of elements that don't necessarily need them (in this case). This could easily be addressed by a classname only for list-items that contain submenus, for instance "folder". In that case the trimmed line would read:
#menu li.folder {
...
}
... effectively selecting only those elements that actually need events. The downside is that you'd be using a classname to get the best performance from the script (disregarding menu-wide li:hovers for purely visual effects), on the other hand you might have used a class anyway to tell these list-items apart from normal items.
To illustrate all this; take a look at the combined example. Enjoy.
Most modern browsers support the :hover selector for any html element. This is cool, because it enables you to, for instance, apply a mouseover effect to table rows <tr> using only CSS. IE however, has an erratic support for :hover at best, depending on the particular version your visitor is using.
Whatever:hover is a small script that automatically patches :hover, :active and :focus for IE6, IE7 and IE8 quirks, letting you use them like you would in any other browser. Version 3 introduces ajax support, meaning that any html that gets inserted into the document via javascript will also trigger :hover, :active and :focus styles in IE.
If you're already familiar with whatever:hover and just want to download it, scroll down and grab the latest version. For some in depth stuff on the other hand, just continue reading.
Getting it to work How do I use it?
Link whatever:hover to the body element, and you're all set. Note that behavior URLs are relative to the html file, not to the CSS file like a background image URL would be.
body {
behavior: url("csshover3.htc");
}
IE only behaviours How does it work?
All browsers provide some way to look at a stylesheet's rules using javascript, and dynamically insert new rules. Normally, IE returns "unknown" for anything it does not support, for instance; a "div p:first-child" would change into "div p:unknown", and a "p a[href]" would be returned as "UNKNOWN" altogether. Fortunately IE recognizes :hover as something it's familiar with, and leaves it alone.
IE also supports so called behaviors; both predefined functionality like dynamic content loading or persistent data storage, as well as custom behaviors that you can build into an .htc or .hta file. These behaviors are linked to html nodes via css, and "enhance" the nodes that are selected by a rule's selector with the given behavior.
Combining the above, it should be possible to create a bahavior that searches the styles for rules IE doens't support, and trick affected elements into applying the associated styles some other way. The steps involved in this are something like:
Search all stylesheets for :hover rules IE doesn't support,
Insert a new rule IE does support, like one with class names,
and finally, set up script events for switching class names.
This way, :hover, :active and :focus can be supported, and as a developer you don't have to do anything except including the behavior. Everything else runs on full automatic.
Unlike versions 1 and 2, version 3 also supports dynamically added html (ajax). The difference is that 1 and 2 actively searched for affected elements onload of the page (so; only once), whereas 3 uses expressions to let nodes do a callback themselves. Read the commented version for more details on this.
for a menu An example of :hover
A common use for :hover is creating menusystems using lists. A dual level menusystem is almost too easy to create using this behavior. For instance, if you would remove the javascript from the suckerfish dropdown, described in the A list apart article and add this behavior to the body, it will work.
Multiple level menus require a different approach though. This is because IE lacks support for the > child selector, which would be perfect to show direct submenus, and not yet the deeper nested ones:
li:hover > ul {
/* no go in IE */
}
There is an alternative way to simulate this, using simple descendant selectors only. A previously described method was based on the use of extra classnames, but an easier way is to use the specificity of CSS. Every CSS rule has a certain importance, which can be determined by simply counting the different elements of a rule. Nodenames count as "1", class, pseuo-class and attribute selectors count as "10", and ids as "100". Take the example below.
ul ul {
display:none;
}
li:hover ul {
display:block;
}
The reason that this works, is because of the specificity. The first rule contains only 2 nodenames, which makes its value 2. The second also contains 2 nodenames, but the :hover pseudo class is worth 10, so the combined value of the rule is 12. Because 12 exceeds 2, a hover on the li will show the ul (or rather all of them) nested within.
So how does this help getting around the > child selector? Well, if a rule of 12 would show all submenu's, all we would have to do is make a rule that is worth more than 12 to hide the next menus. Subsequently, that menu would have to be shown by another rule, again worth even more, and so on. For 3 levels of navigation, the CSS code is surprisingly short:
/* 2 and 13 */
ul ul, li:hover ul ul {
display:none;
}
/* 12 and 23*/
li:hover ul, li:hover li:hover ul {
display:block;
}
This way (and adding more for 4 or more levels) unlimited nesting of menu's can be used, without ever needing extra classnames.
script events mayhem Optimizing
There is just one more thing to consider. The .htc file searches the stylesheet for :hover rules, and attaches a mouseover and mouseout event to elements that in its opinion require a scripted hover effect to work as the css file says. To find those elements, everything after (and including) the :hover is trimmed from the selector, and the resulting elements are selected and processed. A rule like:
#menu li:hover ul {
...
}
... would be trimmed back to this to find all the elements that might need hover events:
#menu li {
...
}
Obviously this would select every single <li> element in the entire menu, attaching events to heaps of elements that don't necessarily need them (in this case). This could easily be addressed by a classname only for list-items that contain submenus, for instance "folder". In that case the trimmed line would read:
#menu li.folder {
...
}
... effectively selecting only those elements that actually need events. The downside is that you'd be using a classname to get the best performance from the script (disregarding menu-wide li:hovers for purely visual effects), on the other hand you might have used a class anyway to tell these list-items apart from normal items.
To illustrate all this; take a look at the combined example. Enjoy.
发表评论
-
navigator h and v
2012-05-08 00:53 802菜单垂直 ul { padding: 0 ... -
css fix
2012-04-13 16:11 657come from http://www.webtoolkit ... -
CSS Note 1
2012-03-25 08:37 6981.对html,body设置background-color区 ... -
網頁設計師必備的顏色選擇器
2012-03-25 08:38 765作為網頁設計師,我們經常會瀏覽網站尋求靈感,很多時我們發 ... -
Reset css (add before all css codes)
2012-03-24 21:09 621<style type="text/css ...
相关推荐
6. **可定制化**:"what-input" 允许开发者自定义样式,通过CSS类名(如 `.what-input-mouse`、`.what-input-keyboard`、`.what-input-touch`)来控制元素在不同输入模式下的视觉反馈。 7. **性能优化**:"what-...
### What-If 分析法详解 #### 一、概述 What-If 分析法是一种用于评估不同假设场景下业务表现的分析方法。这种方法通过模拟不同的条件变化,来预测这些变化可能对业务产生的影响。在实际应用中,What-If 分析能够...
### What-If 分析法详解 #### 一、What-If 分析法概述 What-If(假设分析)是一种在信息系统领域广泛应用的数据分析方法。它主要用于预测不同假设条件下的业务结果,帮助决策者评估各种可能情景的影响。这种方法...
1.1 Internet Explorer Architecture...1.2 IE扩展编程的分类...2.1 What is “Windowless Control”...3.1 如何封装IE控件...” 深入解析: 一、Internet Explorer 架构与扩展编程 1.1 Internet Explorer(IE)...
man,what can I say man,what can I say man,what can I say man,what can I say man,what can I say man,what can I say man,what can I say man,what can I say man,what can I say man,what can I say man,what ...
- **支持大多数IE工具栏**:实现了对多种IE工具栏的支持,使用户能够更好地利用已有的IE扩展。 ### 功能增强 - **支持Alexa工具栏**:添加了对Alexa工具栏的支持,增强了浏览器的功能性。 - **解决默认浏览器设置中...
man,what can I say. man,what can I say. man,what can I say. man,what can I say. man,what can I say. man,what can I say. man,what can I say. man,what can I say. man,what can I say. man,what ...
- **书名**:《技术想要什么》(*What Technology Wants*) - **作者**:凯文·凯利(Kevin Kelly) - **出版社**:Viking Penguin,企鹅集团成员 - **出版时间**:2010年 - **ISBN**:978-0-670-02215-1 - **版权...
弗雷德里克·巴斯夏(Frédéric Bastiat)是法国19世纪的经济学家和政治家,他的作品《所见与所不见》(What Is Seen and What Is Not Seen)是政治经济学的经典著作。巴斯夏在这本书中提出了一个核心观点:在经济...
文档中出现的“IE6”、“IE787”、“IE8”等可能是针对特定IE相关流程或方法的引用。 2. **KPIs**: 文档中提到了“IEKPI”,指的是工业工程师关键绩效指标(Key Performance Indicators),这包括生产率、质量、...
What Is Computer Science
在线编辑器的核心是富文本编辑器(WYSIWYG,What You See Is What You Get)。一种常见的实现方式是使用IFrame,因为IFrame可以让编辑器的内容独立于页面其他部分,避免样式冲突。同时,我们可以利用`...
- **What(什么)**:具体问题或活动的内容。 - **When(何时)**:发生的时间。 - **Where(何处)**:发生的地点。 - **How(如何)**:采取的具体措施或方法。 - **Why(为什么)**:原因或目的。 - **How Much...
在Kotlin编程语言中,`whatif`是一个有趣的扩展,它提供了一种简洁的方式来替代传统的if-else语句。这个工具特别关注了处理null安全和布尔条件的情况,从而简化了代码,增强了可读性。在深入理解`whatif`之前,我们...
6. **系统层面的设置**: 在某些情况下,操作系统级别的设置也可能会导致此问题。例如,如果系统设置了自动打开特定页面,可能需要在系统设置中进行更改。 7. **求助社区**: 如果问题依然存在,可以参考提供的...
【IECollection】是一款专为网页开发者设计的工具,它提供了比ittester更为便捷的方式来测试网页在不同版本的Internet Explorer浏览器中的兼容性和表现。这个工具对于确保网页在多种IE环境下正常运行至关重要,因为...
此外,“W2H”可以解读为“Why-What-How”,这通常用于问题解决和项目管理的上下文中,用来明确问题的根本原因、具体目标和所需采取的措施。 考虑到文档内容中出现的诸如“UPH”(单位产品小时产量,Units Produced...
》(*What is Mathematics?*)是一本享誉全球的数学科普著作,由理查德·科朗(Richard Courant)与赫伯特·罗宾斯(Herbert Robbins)共同编写,并在第二版中加入了伊恩·斯图尔特(Ian Stewart)的新章节。本书自...