<menu>:菜单元素
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
尝试一下
<div class="news">
<a href="#">NASA’s Webb Delivers Deepest Infrared Image of Universe Yet</a>
<menu>
<li><button id="save">Save for later</button></li>
<li><button id="share">Share this news</button></li>
</menu>
</div>
.news {
background-color: bisque;
padding: 1em;
border: solid thin black;
}
menu {
list-style-type: none;
display: flex;
padding: 0;
margin-bottom: 0;
gap: 1em;
}
属性
这个元素只包含全局属性。
使用说明
示例
工具栏
在这个示例中,使用 <menu>
元素创建了一个编辑应用程序的工具栏。
HTML
html
<menu>
<li><button onclick="copy()">复制</button></li>
<li><button onclick="cut()">剪切</button></li>
<li><button onclick="paste()">粘贴</button></li>
</menu>
请注意,这在功能上与以下内容没有区别:
html
<ul>
<li><button onclick="copy()">复制</button></li>
<li><button onclick="cut()">剪切</button></li>
<li><button onclick="paste()">粘贴</button></li>
</ul>
CSS
css
menu,
ul {
display: flex;
list-style: none;
padding: 0;
width: 400px;
}
li {
flex-grow: 1;
}
button {
width: 100%;
}
结果
技术概要
规范
Specification |
---|
HTML # the-menu-element |
浏览器兼容性
BCD tables only load in the browser