简体   繁体   English

如何在不使用 SVG 图像的情况下使用带有文本的 React 创建圆形/方形形状?

[英]How to create circle/square shapes using React with text inside them without using SVG images?

What is the way to create circle and square shapes using React which can contain custom text inside them without using SVG images?使用 React 创建圆形和方形形状的方法是什么,它们可以在其中包含自定义文本而不使用 SVG 图像? An example:一个例子: 在此处输入图片说明

I have tried the following code but it doesn't render any shapes:我尝试了以下代码,但它没有呈现任何形状:

import React from 'react';

export default function Circle(){
  return(
    <div height="110" width="500">
      <circle
        cx="50"
        cy="55"
        r="45"
        fill="none"
        stroke="#F0CE01"
        strokeWidth="4"
      />
    </div>
  );
 }

You can use even a div tag to do that.您甚至可以使用div标签来做到这一点。 Just add border-radius to create a circle.只需添加border-radius即可创建一个圆。

React example: https://codesandbox.io/s/shapes-qbf1f反应示例: https : //codesandbox.io/s/shapes-qbf1f

Here is a snippet for a quick overview:这是一个快速概述的片段:

 .square { display: flex; width: 100px; height: 100px; background-color: red; } .circle { display: flex; width: 100px; height: 100px; background-color: green; border-radius: 50%; } .text { margin: auto; }
 <div class="square"> <p class="text">Square text</p> </div> <div class="circle"> <p class="text">Circle text</p> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM