React js 语义化菜单项居中

huangapple go评论73阅读模式
英文:

React js Semantic Menu items on center

问题

你好,我有困难将我的内容放在这个 div 的中央。

代码:
https://codesandbox.io/s/hungry-https-c5432

我尝试将内联显示放在 h5 上,但仍然不起作用。

<div className="App">
  <Menu
    className="borderless"
    style={{ width: "240px", height: "100vh" }}
    vertical
  >
    <Menu.Item className="logo">
      <Image src={logo} style={{ width: "50px", height: "50px" }} />
      <h5>E M A S A</h5>
      <Divider style={{ color: "#000 !important" }} />
    </Menu.Item>
  </Menu>
</div>

CSS:

.ui.menu {
  border-radius: 0px !important;
  border: 0px !important;
  box-shadow: none !important;
  background-color: #252631 !important;
}
.ui.menu .item {
  padding: 8px !important;
}
r {
  margin-bottom: 0 !important;
}r {
  margin-bottom: 0 !important;
}
英文:

Hello I am having trouble leaving my content at the center of this div

code :
https://codesandbox.io/s/hungry-https-c5432

I tried to put the inline display on h5 and it still didn't work

&lt;div className=&quot;App&quot;&gt;
  &lt;Menu
    className=&quot;borderless&quot;
    style={{ width: &quot;240px&quot;, height: &quot;100vh&quot; }}
    vertical
  &gt;
    &lt;Menu.Item className=&quot;logo&quot;&gt;
      &lt;Image src={logo} style={{ width: &quot;50px&quot;, height: &quot;50px&quot; }} /&gt;
      &lt;h5&gt;E M A S A&lt;/h5&gt;
      &lt;Divider style={{ color: &quot;#000 !important&quot; }} /&gt;
    &lt;/Menu.Item&gt;
  &lt;/Menu&gt;
&lt;/div&gt;

css:

.ui.menu {
  border-radius: 0px !important;
  border: 0px !important;
  box-shadow: none !important;
  background-color: #252631 !important;
}
.ui.menu .item {
  padding: 8px !important;
}
r {
  margin-bottom: 0 !important;
}r {
  margin-bottom: 0 !important;
}

答案1

得分: 2

要将<b>img</b>居中对齐,您可以添加
margin: 0 auto;
display: block;

要将<b>h5</b>文本居中对齐,您可以添加
text-align: center;

查看此链接:https://codesandbox.io/embed/sweet-glitter-9toif?fontsize=14&hidenavigation=1&theme=dark

英文:

In order to align the <b>img</b> to center you can add
margin: 0 auto;
display: block;

and for aligning the text <b>h5</b> you can add
text-align: center;

Check this link: https://codesandbox.io/embed/sweet-glitter-9toif?fontsize=14&amp;hidenavigation=1&amp;theme=dark

答案2

得分: 1

将以下内容翻译为中文:

"我明白您需要它们在同一行上,因此请将以下内容添加到CSS中:.ui.vertical.menu .item{display:flex; justify-content:center;}"

英文:

i understood you need them on the same line so add this to the css .ui.vertical.menu .item{display:flex;
justify-content:center;}

答案3

得分: 0

需要更新CSS,以下是演示链接

JSX 代码

<Menu
  className="borderless"
  style={{ width: "240px", height: "100vh" }}
  vertical
>
  <Menu.Item className="logo">
    <h5>
      <Image
        src={logo}
        style={{ width: "50px", height: "50px", marginRight: "10px" }}
      />
      <span>E M A S A</span>
    </h5>
    <Divider style={{ color: "#000 !important" }} />
  </Menu.Item>
</Menu>

CSS

.ui.menu {
  border-radius: 0px !important;
  border: 0px !important;
  box-shadow: none !important;
  background-color: #252631 !important;
}

.ui.menu .item {
  padding: 8px !important;
  text-align: center;
}

.ui.menu .item h5 {
  text-align: center;
}

.ui.divider {
  margin-bottom: 0 !important;
}

img.ui.image {
  display: inline-block;
}
英文:

You need to update CSS, Here is the demo link

> JSX Code

 &lt;Menu
    className=&quot;borderless&quot;
    style={{ width: &quot;240px&quot;, height: &quot;100vh&quot; }}
    vertical&gt;
    &lt;Menu.Item className=&quot;logo&quot;&gt;
      &lt;h5&gt;
        &lt;Image
          src={logo}
          style={{ width: &quot;50px&quot;, height: &quot;50px&quot;, marginRight: &quot;10px&quot; }}
        /&gt;
        &lt;span&gt;E M A S A&lt;/span&gt;
      &lt;/h5&gt;
      &lt;Divider style={{ color: &quot;#000 !important&quot; }} /&gt;
    &lt;/Menu.Item&gt;
  &lt;/Menu&gt;

> CSS

.ui.menu {
  border-radius: 0px !important;
  border: 0px !important;
  box-shadow: none !important;
  background-color: #252631 !important;
}

.ui.menu .item {
  padding: 8px !important;
  text-align: center;
}

.ui.menu .item h5 {
  text-align: center;
}

.ui.divider {
  margin-bottom: 0 !important;
}

img.ui.image {
  display: inline-block;
}

huangapple
  • 本文由 发表于 2020年1月6日 18:10:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/59610163.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定