首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Material-ui水平菜单

Material-ui水平菜单
EN

Stack Overflow用户
提问于 2016-11-18 07:24:56
回答 2查看 10K关注 0票数 1

我正在尝试从material UI创建一个水平菜单组件,但似乎无法做到,因为所有列表项都包装在一个<div>

docs将显示垂直菜单列表

有效的方法是删除跨度内的所有外部divs,并删除应用于跨度的display: block样式。

代码语言:javascript
复制
<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>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-11-18 07:43:52

在菜单上用“className : inline-block”设置直接DIV子对象样式的CSS

工作jsFiddle:https://jsfiddle.net/d980vcon/2/

在CSS中:

代码语言:javascript
复制
.horiz-menu > div {
  display: inline-block;
}

在JSX中:

代码语言:javascript
复制
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>
    );
  }
}
票数 2
EN

Stack Overflow用户

发布于 2018-04-26 23:57:34

您可以使用flex作为您的css的一部分,在您的菜单中,您可以使用属性className="myStyle"进行样式设置,如下所示:

代码语言:javascript
复制
.myStyle {
    display: 'flex',
    flexWrap: 'wrap',
    justifyContent: 'space-around',
    overflow: 'hidden'
}

作为css的一部分。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40666857

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档