<!DOCTYPE html>
<html>
<head>
<title>鼠标悬停显示/隐藏菜单</title>
<style>
.container {
align-items: flex-start;
}
.subnav {
position: relative; /* 添加相对定位 */
width: 200px;
}
.subnav ul {
display: none;
position: fixed;
top: 0;
left: 111px;
width: 300px; /* 调整宽度 */
box-shadow: 0 1px 2px #222;
list-style: none;
padding: 0;
/* 添加多列布局样式 */
columns: 2;
-webkit-columns: 2;
-moz-columns: 2;
}
.subnav li {
height: 40px;
text-align: center;
line-height: 40px;
background: white;
margin-right: 10px; /* 可选,用于设置列表项之间的间距 */
/* 设置列宽度 */
break-inside: avoid;
-webkit-column-break-inside: avoid;
-moz-column-break-inside: avoid;
}
.subnav:hover ul {
display: block;
}
.subnav li:hover {
color: red;
}
</style>
</head>
<body>
<div class="container">
<div class="subnav">
<a href="#">菜单按钮1</a>
<ul>
<li>菜单项1</li>
<li>菜单项2</li>
<li>菜单项3</li>
</ul>
</div>
<br><br><br>
<div class="subnav">
<a href="#">菜单按钮2</a>
<ul>
<li>菜单项4</li>
<li>菜单项5</li>
<li>菜单项6</li>
</ul>
</div>
</div>
</body>
</html>