Home > Web Front-end > CSS Tutorial > How Can I Create and Style Circles Using HTML5 and CSS3?

How Can I Create and Style Circles Using HTML5 and CSS3?

Susan Sarandon
Release: 2024-11-23 12:25:16
Original
552 people have browsed it

How Can I Create and Style Circles Using HTML5 and CSS3?

Drawing Circles in HTML5 and CSS3

Although HTML5 and CSS3 do not have native support for drawing circles directly, it is possible to replicate the appearance of a circle using innovative techniques.

Creating a Circle with Rounded Corners

To simulate a circle, you can create a rectangular element and apply rounded corners to it. The radius of the rounded corners should be half the desired width or height of the circle you want to create.

For example, the following code creates a red circle with a diameter of 50 pixels:

#circle {
  width: 50px;
  height: 50px;
  -webkit-border-radius: 25px;
  -moz-border-radius: 25px;
  border-radius: 25px;
  background: red;
}
Copy after login
<div>
Copy after login
Copy after login

Adding Text Inside a Circle

To add text inside the circle, position the text element absolutely within the circle container and center it align it vertically and horizontally.

#circle {
  position: relative;
}

#text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}
Copy after login
<div>
Copy after login
Copy after login

The above is the detailed content of How Can I Create and Style Circles Using HTML5 and CSS3?. 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