1

https://codesandbox.io/embed/material-demo-g5pez?fontsize=14&hidenavigation=1&theme=dark

enter image description here

<span>
    {

        item.result.map((item, idx) => {
            return <span className="legend-label">
                <StopIcon />{item.metric}: {item.count}</span>
        })
    }
</span>

I am rendering material-icon and putting a text next to it. However, I am not sure how to make them vertically align with the RIGHT practice. Of course, I can put top or bottom attribute to style to make a tweak, but I believe that is not the right practice of doing this.

What is the right way to do this without generating a bad aftermath?

Dawn17
  • 7,825
  • 16
  • 57
  • 118

3 Answers3

10

https://codesandbox.io/s/material-demo-u71qr

Just add some style to the legend-label:

display: inline-flex;
align-items: center;
Loi Nguyen Huynh
  • 8,492
  • 2
  • 29
  • 52
1

Making use of css flex is one option:

<span style={{ display:'inline-flex', alignItems: 'center' }} className="legend-label">
  <StopIcon style={{ color: palette[idx] }} />
  {item.metric}: {item.count}
</span>
0
     <span>
        {objarr.map((item, idx) => {
          return (
            <span style={{display:'flex', alignItems:'center'}} className="legend-label">
              <StopIcon style={{ color: palette[idx] }} />
              {item.metric}: {item.count}
            </span>
          );
        })}
      </span>
akhtarvahid
  • 9,445
  • 2
  • 26
  • 29