最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Align content to center with variant as caption in Material UI Typography - Stack Overflow

programmeradmin1浏览0评论

I have two Typography elements with default and caption variants. How do I center the content with align="center" property with variant as caption as this doesn't seem to work.

  render() {
    return (
      <div>
        <Typography align="center">Centered text</Typography>
        <Typography color="textSecondary" variant="caption" align="center">A Caption!</Typography>
      </div>
    );
  }

I created a working example using StackBlitz. Could anyone please help?

I have two Typography elements with default and caption variants. How do I center the content with align="center" property with variant as caption as this doesn't seem to work.

  render() {
    return (
      <div>
        <Typography align="center">Centered text</Typography>
        <Typography color="textSecondary" variant="caption" align="center">A Caption!</Typography>
      </div>
    );
  }

I created a working example using StackBlitz. Could anyone please help?

Share Improve this question asked Jul 28, 2020 at 18:01 scriobhscriobh 90012 silver badges27 bronze badges 2
  • variant="caption" is belongs to span thats why its not working – Raj Kumar Commented Jul 28, 2020 at 18:24
  • @RajKumar Got it! Figured a way by wrapping the element in a Box and style my ponent. – scriobh Commented Jul 29, 2020 at 0:28
Add a ment  | 

1 Answer 1

Reset to default 7
import React from "react";
import Typography from "@material-ui/core/Typography";

export default function DisableElevation() {
  return (
    <div>
      <Typography align="center">Centered text</Typography>
      <Typography
        display="block"
        color="textSecondary"
        variant="caption"
        align="center"
      >
        A Caption!
      </Typography>
    </div>
  );
}
发布评论

评论列表(0)

  1. 暂无评论