gpt4 book ai didi

CSS 相邻兄弟选择器 - IE8 问题

转载 作者:技术小花猫 更新时间:2023-10-29 11:30:10 27 4
gpt4 key购买 nike

我正在使用 UL/LI 结构创建菜单系统。我正在尝试将兄弟选择器用于悬停/显示子菜单。

我正在使用这个;

#MainMenu li.Sel ul li.HasSub a:hover+ul {
display: block;
}

UL 结构大概是这样的;

<ul id='MainMenu'>
<li class='Sel'>
<a href='#'>Click Me</a>
<ul>
<li class='HasSub'>
<a href='#'>Hover Over Me</a>
<ul>
<li>Link</li>
<li>Link</li>
</ul>
</li>
</ul>
</li>
</ul>

据推测,当悬停在“悬停在我身上”时,应该显示兄弟 ul。它在 Firefox 中运行良好,但在 IE8 中则完全无效。我确定我以前见过 IE8 中使用的“+”同级选择器,我哪里出错了?

最佳答案

您需要确保 IE 以标准模式运行 - 输入如下文档类型:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">

来自 the documentation :

The adjacent sibling combinator is a "plus sign" (+) character that separates two simple selectors. Whitespace is not significant.

A selector of the form "E+F" matches element F when it immediately follows sibling element E in the document tree, ignoring non-element nodes (such as text nodes and comments). Element E and F must share the same parent and E must immediately precede F. To match the first child of the parent, use the :first-child pseudo-class.

Note Requires Windows Internet Explorer 7 or later.
Note Combinators are enabled only in standards-compliant mode (strict !DOCTYPE).

关于CSS 相邻兄弟选择器 - IE8 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1612587/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com