为了使两个导航菜单具有相同的宽度,可以采取以下几种方法:
<style>
.container {
display: flex;
}
.menu {
flex: 1;
}
</style>
<div class="container">
<ul class="menu">
<li>菜单项1</li>
<li>菜单项2</li>
<li>菜单项3</li>
</ul>
<ul class="menu">
<li>菜单项4</li>
<li>菜单项5</li>
<li>菜单项6</li>
</ul>
</div>
推荐的腾讯云相关产品:腾讯云云服务器(CVM),产品介绍链接地址:https://cloud.tencent.com/product/cvm
<style>
.container {
display: grid;
grid-template-columns: 1fr 1fr;
}
.menu {
grid-column: 1/2;
}
</style>
<div class="container">
<ul class="menu">
<li>菜单项1</li>
<li>菜单项2</li>
<li>菜单项3</li>
</ul>
<ul class="menu">
<li>菜单项4</li>
<li>菜单项5</li>
<li>菜单项6</li>
</ul>
</div>
推荐的腾讯云相关产品:腾讯云云服务器(CVM),产品介绍链接地址:https://cloud.tencent.com/product/cvm
<script>
window.onload = function() {
var menu1 = document.getElementById("menu1");
var menu2 = document.getElementById("menu2");
var maxWidth = Math.max(menu1.offsetWidth, menu2.offsetWidth);
menu1.style.width = maxWidth + "px";
menu2.style.width = maxWidth + "px";
};
</script>
<ul id="menu1">
<li>菜单项1</li>
<li>菜单项2</li>
<li>菜单项3</li>
</ul>
<ul id="menu2">
<li>菜单项4</li>
<li>菜单项5</li>
<li>菜单项6</li>
</ul>
推荐的腾讯云相关产品:腾讯云云服务器(CVM),产品介绍链接地址:https://cloud.tencent.com/product/cvm
领取专属 10元无门槛券
手把手带您无忧上云