css - 如何使用 React Material-UI、fontAwesome 图标和 Tailwind.css 左对齐所有列表项

标签 css reactjs font-awesome material-ui tailwind-css

我想左对齐列表项的文本。目前,我有这个:

enter image description here

如何左对齐文本?

import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import List from '@material-ui/core/List';
import ListItem from '@material-ui/core/ListItem';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faFacebook, faGoogle, faGooglePlus, faTwitter, faYoutube, } from '@fortawesome/free-brands-svg-icons';
import { faEnvelope, } from '@fortawesome/free-solid-svg-icons';

const styles = theme => ({
  root: {
    width: '100%',
    maxWidth: 360,
    backgroundColor: theme.palette.background.paper,
  },
});

const items = [
  { label : 'Google'     , icon : faGoogle     , } ,
  { label : 'Twitter'    , icon : faTwitter    , } ,
  { label : 'Gmail'      , icon : faEnvelope   , } ,
  { label : 'Facebook'   , icon : faFacebook   , } ,
  { label : 'Youtube'    , icon : faYoutube    , } ,
  { label : 'GooglePlus' , icon : faGooglePlus , } ,
]

function LoginList(props) {
  const { classes } = props;
  return (
    <div className={classes.root}>
      <List component='nav'>
       {
         items.map( item => (
           <ListItem button key={item.label}>
             <ListItemIcon>
               <FontAwesomeIcon className='text-4xl' icon={item.icon} />
             </ListItemIcon>
             <ListItemText primary={`Login with ${item.label}`} />
           </ListItem>
         ))
       }
      </List>
    </div>
  );
}

LoginList.propTypes = {
  classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(LoginList);

最佳答案

此时,既然您已经实现了字体大小,请在 ListItemIcon 元素的类中使用 width,例如 24px。

...
const styles = theme => ({
  listItemIcon: 24,
});

...

<ListItemIcon className={classes.listItemIcon}>
 <FontAwesomeIcon className='text-4xl' icon={item.icon} />
</ListItemIcon>

enter image description here

关于css - 如何使用 React Material-UI、fontAwesome 图标和 Tailwind.css 左对齐所有列表项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52957859/

相关文章:

html - 如何用 "shared border"创建多个 div?

html - Figcaption 宽度不适合图像 - 'width: fit-content' 无效

javascript - 在 SCSS 中动态堆叠图像

reactjs - 如果弹出窗口打开,React 会阻止正文滚动

javascript - 没有第二个参数或一个等于 null 或 undefined 的 useEffect 会发生什么?

css - 动画 Font Awesome 堆栈以在悬停时旋转图标

html - 位置 h1,边框位于图片中心

reactjs - react-native 中的 event.target.value

使用 tailwindcss 的超棒字体响应大小

twitter-bootstrap - 如何在不更改 HTML 的情况下在 Bootstrap 3 中用 FontAwesome 替换 Glyphicons?