Home >Web Front-end >CSS Tutorial >How to Center Text within a CSS-Drawn Circle?

How to Center Text within a CSS-Drawn Circle?

Linda Hamilton
Linda HamiltonOriginal
2024-12-07 02:01:11659browse

How to Center Text within a CSS-Drawn Circle?

How to Draw a Circle with Text in the Center

To create a circle with text in the middle using CSS, modify the code used to draw the circle:

  1. Set line-height to match the height of the div. This forces a single line of text to appear vertically centered. In the example below, the height and line-height are both set to 500px.
.circle {
  width: 500px;
  height: 500px;
  line-height: 500px;
  border-radius: 50%;
  font-size: 50px;
  color: #fff;
  text-align: center;
  background: #000
}
  1. Add text to the div. Wrap the desired text within the
    element.
<div class="circle">Hello I am A Circle</div>

This code will create a centered circle with the text "Hello I am A Circle" positioned in the middle.

The above is the detailed content of How to Center Text within a CSS-Drawn Circle?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn