我尝试从素材用户界面创建水平菜单组件,但似乎我无法将所有列表项都包含在<div>
docs显示垂直菜单列表
如果删除范围内的所有外部divs
,并删除应用于范围的display: block
样式,则有效。
<div style="padding: 8px 0px;">
<div>
<span tabindex="0" type="button" style="border: 10px; box-sizing: border-box; display: block; font-family: Roboto, sans-serif; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); cursor: pointer; text-decoration: none; margin: 0px; padding: 0px; outline: none; font-size: 16px; font-weight: inherit; transform: translate(0px, 0px); color: rgba(0, 0, 0, 0.870588); line-height: 16px; position: relative; transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms; background: none;">
<div>
<div style="margin-left: 0px; padding: 16px; position: relative;">
<div>Inbox</div>
</div>
</div>
</span>
</div>
<div>
<span tabindex="0" type="button" style="border: 10px; box-sizing: border-box; display: block; font-family: Roboto, sans-serif; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); cursor: pointer; text-decoration: none; margin: 0px; padding: 0px; outline: none; font-size: 16px; font-weight: inherit; transform: translate(0px, 0px); color: rgba(0, 0, 0, 0.870588); line-height: 16px; position: relative; transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms; background: none;">
<div>
<div style="margin-left: 0px; padding: 16px; position: relative;">
<div>Starred</div>
</div>
</div>
</span>
</div>
<div>
<span tabindex="0" type="button" style="border: 10px; box-sizing: border-box; display: block; font-family: Roboto, sans-serif; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); cursor: pointer; text-decoration: none; margin: 0px; padding: 0px; outline: none; font-size: 16px; font-weight: inherit; transform: translate(0px, 0px); color: rgba(0, 0, 0, 0.870588); line-height: 16px; position: relative; transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms; background: none;">
<div>
<div style="margin-left: 0px; padding: 16px; position: relative;">
<div>Sent mail</div>
</div>
</div>
</span>
</div>
<div>
<span tabindex="0" type="button" style="border: 10px; box-sizing: border-box; display: block; font-family: Roboto, sans-serif; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); cursor: pointer; text-decoration: none; margin: 0px; padding: 0px; outline: none; font-size: 16px; font-weight: inherit; transform: translate(0px, 0px); color: rgba(0, 0, 0, 0.870588); line-height: 16px; position: relative; transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms; background: none;">
<div>
<div style="margin-left: 0px; padding: 16px; position: relative;">
<div>Drafts</div>
</div>
</div>
</span>
</div>
<div>
<span tabindex="0" type="button" style="border: 10px; box-sizing: border-box; display: block; font-family: Roboto, sans-serif; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); cursor: pointer; text-decoration: none; margin: 0px; padding: 0px; outline: none; font-size: 16px; font-weight: inherit; transform: translate(0px, 0px); color: rgba(0, 0, 0, 0.870588); line-height: 16px; position: relative; transition: all 450ms cubic-bezier(0.23, 1, 0.32, 1) 0ms; background: none;">
<div>
<div style="margin-left: 0px; padding: 16px; position: relative;">
<div>Inbox</div>
</div>
</div>
</span>
</div>
</div>
答案 0 :(得分:0)
您可以将flex
用作css的一部分,您可以在菜单中使用属性className="myStyle"
进行访问,以便进行样式设置:
.myStyle {
display: 'flex',
flexWrap: 'wrap',
justifyContent: 'space-around',
overflow: 'hidden'
}
作为你的css的一部分。
答案 1 :(得分:-1)
在菜单上设置CSS className,使用“display:inline-block”为其直接DIV子项设置样式
工作jsFiddle:https://jsfiddle.net/d980vcon/2/
CSS中的:
.horiz-menu > div {
display: inline-block;
}
在JSX中:
class Example extends React.Component {
render() {
return (
<Menu className="horiz-menu">
<MenuItem primaryText="Home"/>
<MenuItem primaryText="Test Menu 1" />
<MenuItem primaryText="Test Menu 2" />
<MenuItem primaryText="About" />
</Menu>
);
}
}