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
Release: 2024-12-07 02:01:11
Original
591 people have browsed it

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
}
Copy after login
  1. Add text to the div. Wrap the desired text within the
    element.
<div class="circle">Hello I am A Circle</div>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template