【问题标题】:Style Typography with css带有 css 的样式排版
【发布时间】:2021-08-03 03:14:36
【问题描述】:

我正在尝试使用 CSS 文件对 Material UI 中的 Typography 进行样式设置,但我所做的样式并未应用于我的 React 网站。任何帮助将不胜感激!

我想用 className ".title-card" 来设置 Typography 的样式,下面你会找到对应的 js 和 css 文件

import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Grid from '@material-ui/core/Grid';
import Paper from '@material-ui/core/Paper';
import Typography from '@material-ui/core/Typography';
import ButtonBase from '@material-ui/core/ButtonBase';
import stockPhoto from '../images/home-stock-image.png';
import Card from '@material-ui/core/Card';
import CardActionArea from '@material-ui/core/CardActionArea';
import CardActions from '@material-ui/core/CardActions';
import CardContent from '@material-ui/core/CardContent';
import CardMedia from '@material-ui/core/CardMedia';
import { CardHeader } from '@material-ui/core';
import '../styling/SmallCard.css'


const useStyles = makeStyles((theme) => ({
  root: {
    flexGrow: 1,
  },
  paper: {
    padding: theme.spacing(2),
    margin: 'auto',
    maxWidth: 500,
  },
  image: {
    width: 128,
    height: 128,
  },
  img: {
    margin: 'auto',
    display: 'block',
    maxWidth: '100%',
    maxHeight: '100%',
  },
  //having trouble setting dimensions of card
  style: 
    {minWidth: "5000px", margin: '12px'},

}));

var cardStyle = {
  width: '424px',
  height: '466px',
  left: '64px',
  top: '761px'

}

export default function SmallCard({submission}) {
  const classes = useStyles();
  return (
    <div>

      { /*{submission.title}*/ }
      <Card style={cardStyle}>
        <CardMedia
            component="img"
            alt="Contemplative Reptile"
            height="180"
            image={stockPhoto}
            title="Contemplative Reptile"
          />
          <CardContent>
          <Typography className=".title-card"  gutterBottom variant="h5" component="h2">
            London, England
          </Typography>
          <Typography variant="body2" color="textSecondary" component="p">
          3 Apr 1944
          </Typography>
        </CardContent>

      </Card>
    </div>
    
  );
}

.title-card {
    font-family: Open Sans;
    font-style: normal;
    font-weight: bold;
    font-size: 24px;
    line-height: 33px;
}

我想应用相应的字体和文字更改但没有应用

【问题讨论】:

    标签: css reactjs material-ui


    【解决方案1】:

    必须引用带空格的字体系列:

    font-family: "Open Sans";
    

    同时修正你的错字:

    <Typography className=".title-card
    

    删除点。

    【讨论】:

      【解决方案2】:

      className=".title-card" 中删除.

      <Typography className="title-card"  gutterBottom variant="h5" component="h2">
      

      【讨论】:

        猜你喜欢
        • 2010-11-06
        • 2014-08-06
        • 2019-03-15
        • 2016-01-18
        • 1970-01-01
        • 1970-01-01
        • 2023-03-29
        • 1970-01-01
        相关资源
        最近更新 更多