我设置了一个菜单,其中伪元素用作背景颜色。需要伪元素,因为虽然菜单本身不是全宽,但背景必须如此。我已经设置了我认为非常简单的元素。
这是我的带评论的HTML
<div class="primary-menu">
<nav class="menu-primary-menu-container">
<ul id="menu-primary-menu" class="menu">
<li id="menu-item-7031" class="first-menu-item menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-7031">
//hovering this li triggers the sub-menu visibility, the pseudo element is also lined up to this element
<a href="#">Solutions</a>
<ul class="sub-menu">
//pseudo element should show up here
<li id="menu-item-8916" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-8916"><a href="#">Solutions Overview</a></li>
<li id="menu-item-7787" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-7787"><a href="#">Data Lake</a></li>
<li id="menu-item-7541" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-7541"><a href="#">Real-Time Analytics</a></li>
<li id="menu-item-7540" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-7540"><a href="#">Cloud Data Integration</a>
<ul class="sub-menu">
<li id="menu-item-7854" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-7854"><a href="#">Data Integration into Azure</a>
<ul class="sub-menu">
<li id="menu-item-8393" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-8393"><a href="#">Azure FAQ</a></li>
<li id="menu-item-8394" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-8394"><a href="#">Getting Started with Azure</a></li>
</ul>
</li>
<li id="menu-item-7853" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-has-children menu-item-7853"><a href="#">Data Integration into AWS</a>
<ul class="sub-menu">
<li id="menu-item-11470" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-11470"><a href="#">Getting Started with AWS</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
</div>
相关的CSS
@media (min-width: 768px)
.primary-menu .menu-primary-menu-container #menu-primary-menu > li {
margin: 0 15px;
position: relative;
}
}
.primary-menu #menu-primary-menu > li > .sub-menu:before {
-ms-flex-item-align: center;
-ms-grid-row-align: center;
align-self: center;
background: rgba(255, 255, 255, 0.9);
box-shadow: 0 4px 4px rgba(0, 0, 0, 0.2);
content: "";
display: block;
height: 470px;
position: absolute;
top: -1rem;
width: calc(100vw + 1400px);
z-index: -1;
}
在IE11中,伪元素的属性全部被删除并应用于before元素应该生成的.sub-menu ul。我添加了一个显示:块;每the suggestion here的财产,但这对我的问题没有帮助。
当我检查元素时,这是IE11中显示的内容。
I have a working code pen here which also displays the issue.
答案 0 :(得分:1)
根据我的经验,您无法使用IE检查::after
或::before
,因此所有属性都已被删除,只是因为在某种程度上它们不属于选择的元素本身,但它的pesudo。
我发现让它看起来像在其他浏览器中的唯一方法是更改::before
样式的某些属性值:
header .wrapper .primary-menu #menu-primary-menu > li > .sub-menu::before {
-ms-flex-item-align: center;
-ms-grid-row-align: center;
align-self: center;
background: rgba(255, 255, 255, 0.9);
box-shadow: 0 4px 4px rgba(0, 0, 0, 0.2);
content: "";
display: block;
height: 470px;
position: absolute;
top: -1rem;
/* Set width to auto */
width: auto;
z-index: -1;
/* Make a huge overflow (i doesn't have to be that big) */
right: -9999px;
left: -9999px;
}
希望它有所帮助。