下面的代码创建了一个mathjax公式的下拉菜单。有时当我将鼠标光标移动到菜单元素时,菜单会消失。如果我慢慢移动光标,则更常见。所以,我无法选择任何菜单元素。
以下是代码:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
background-color: #f1f1f1
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
</style>
</head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>
<body>
<h2>Hoverable Dropdown</h2>
<p>Move the mouse over the button to open the dropdown menu.</p>
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
<br/><math><mi>a</mi><mo>≠</mo><mn>0</mn></math><math><mi>a</mi><mo>≠</mo><mn>0</mn></math>
<br/><math><mi>a</mi><mo>≠</mo><mn>0</mn></math><math><mi>a</mi><mo>≠</mo><mn>0</mn></math>
<br/><math><mi>a</mi><mo>≠</mo><mn>0</mn></math><math><mi>a</mi><mo>≠</mo><mn>0</mn></math>
</body>
</html>
&#13;
您可以找到完整示例here
为什么会这样?我该如何解决?
答案 0 :(得分:1)
您可以使用:before
添加帮助,以填补悬停时的空白:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown:hover:before{
content:'';
position: absolute;
top:0;
left:0;
bottom:-25px;
right:0;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
background-color: #f1f1f1
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
</style>
</head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script>
<body>
<h2>Hoverable Dropdown</h2>
<p>Move the mouse over the button to open the dropdown menu.</p>
<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
<br/><math><mi>a</mi><mo>≠</mo><mn>0</mn></math><math><mi>a</mi><mo>≠</mo><mn>0</mn></math>
<br/><math><mi>a</mi><mo>≠</mo><mn>0</mn></math><math><mi>a</mi><mo>≠</mo><mn>0</mn></math>
<br/><math><mi>a</mi><mo>≠</mo><mn>0</mn></math><math><mi>a</mi><mo>≠</mo><mn>0</mn></math>
</body>
</html>
答案 1 :(得分:1)
将z-index:1
添加到您的.dropdown
样式,并且应该处理它。按钮下方的MathJax输出略微与按钮重叠,因此使用z-index
,您可以按下按钮。