我有一个旧程序,它从Java源文件生成html文件,以提供从使用到定义和交叉引用的超链接。生成的文件使用PRE html标记来保留源格式。 交叉引用在Javascript菜单中运行良好,但不再支持这些菜单,因此我可以使用css菜单解决方案。
问题是我的菜单相对于PRE文本显示在垂直对齐中。我尝试调整风格没有效果。 任何帮助表示赞赏。
这是我的css:
.dropbtn {
color: black;
/*padding: 16px;*/
//font-size: 16px;
border: none;
cursor: pointer;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
position: relative;
display: inline-block;
}
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
left: 30px;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
/* Links inside the dropdown */
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {
background-color: #cde
}
/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
.show {
display:block;
}
这是我的html正文:
Some text <div class="dropdown">
<a href="#" onclick="myFunction('myDropdown1')" class="dropbtn">Dropdown</a>
<div id="myDropdown1" class="dropdown-content">
<a href="#2">Link 1</a>
<div class="dropdown">
<a href="#" onclick="myFunction('myDropdown3')" class="dropbtn">Link1.1</a>
<div id="myDropdown3" class="dropdown-content">
<a href="#2">Link 1.2</a>
</div>
</div>
<a href="#3">Link 2</a>
<a href="#1">Link 3</a>
</div>
</div> around a button.
Write some text around a button<div class="dropdown">
<button onclick="myFunction('myDropdown2')" class="dropbtn">Link</button>
<div id="myDropdown2" class="dropdown-content">
<a href="#2">Link 4</a>
<a href="#3">Link 5</a>
<a href="#1">Link 6</a>
</div>
</div>Let see if this works!
这是我最后的脚本部分:
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function myFunction(dropDownLink) {
document.getElementById(dropDownLink).classList.toggle("show");
}
// Close the dropdown menu if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}