javascript - How to make texts appear below icons in Buttons (Material UI) - Stack Overflow

Basically, this is my Button right nowI want to make the Dummy Button text to appear below the icon, ho

Basically, this is my Button right now

I want to make the Dummy Button text to appear below the icon, how do I do that?
Here is my code

<Button className={classes.dummyButton}>
  <Image
   src="/buttonImage1.webp"
   alt="buttonimage1"
   width={48}
   height={48}
   />
<span>Dummy Button</span>
</Button>

Styles.js

dummyButton: {
    backgroundColor: 'green',
  },

Basically, this is my Button right now

I want to make the Dummy Button text to appear below the icon, how do I do that?
Here is my code

<Button className={classes.dummyButton}>
  <Image
   src="/buttonImage1.webp"
   alt="buttonimage1"
   width={48}
   height={48}
   />
<span>Dummy Button</span>
</Button>

Styles.js

dummyButton: {
    backgroundColor: 'green',
  },
Share Improve this question edited Feb 19, 2022 at 6:44 gem173 asked Feb 19, 2022 at 6:08 gem173gem173 372 silver badges10 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 2

You want to set display: 'flex' and flexDirection: 'column' for column-direction elements placement inside your button:

dummyButton: {
    backgroundColor: 'green',
    display: 'flex',
    flexDirection: 'column'
  },

I was trying to recreate the youtube bottom bar, and here is what I came up with.

<AppBar position="fixed" sx={{ top: 'auto', bottom: 0 }}>
  <Toolbar sx={{ justifyContent: 'space-between' }}>
    <IconButton color="inherit" sx={{ flexDirection: 'column' }}>
      <AssignmentTurnedIn />
      <Typography variant="caption">Tasks</Typography>
    </IconButton>

    <IconButton color="inherit" sx={{ flexDirection: 'column' }}>
      <CalendarMonth />
      <Typography variant="caption">Events</Typography>
    </IconButton>

    <IconButton color="inherit" sx={{ flexDirection: 'column' }}>
      <FitnessCenter />
      <Typography variant="caption">Habits</Typography>
    </IconButton>
  </Toolbar>
</AppBar>

I think you can put your image tag in another span and change its display to block.

Try this:

<Button className={classes.dummyButton}>
 <span className={classes.mySpan}>
  <Image
   src="/buttonImage1.webp"
   alt="buttonimage1"
   width={48}
   height={48}
   />
</span>
<div>Dummy Button</div>
</Button>

and your class styles should be like this:

.mySpan {
       display: 'block'
    }

try To add A <br /> tag between image and div. This what I meant. This will help you https://codepen.io/ash_000001/pen/OJOQaGp?editors=1100

<Button className={classes.dummyButton}>
  <Image
   src="/buttonImage1.webp"
   alt="buttonimage1"
   width={48}
   height={48}
   />

<div>Dummy Button</div>
</Button>
Styles.js

dummyButton: {
    backgroundColor: 'green',
 
  },

It is semantically "incorrect" to use a div in a button. You should use the span element instead.

With that being said, the Button ponent uses flexbox to control the layout/alignment of content. To align the content vertically (so the icon is above the text), you can simply change the flex-direction to column.

style.js

dummyButton: {
    backgroundColor: 'green',
    flexDirection: 'column'
  },
<Button className={classes.dummyButton}>
  <Image
   src="/buttonImage1.webp"
   alt="buttonimage1"
   width={48}
   height={48}
   />
   <span>Dummy Button</span>
</Button>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744909977a4600487.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信