Home > Web Front-end > CSS Tutorial > How to implement a circular image using pure CSS?

How to implement a circular image using pure CSS?

不言
Release: 2019-04-13 16:27:27
Original
3311 people have browsed it

CSS can achieve many effects in web pages, so how do we use pure CSS to achieve circular images? In this article, we will introduce the method of realizing circular images with CSS. Let’s take a look at the specific content.

How to implement a circular image using pure CSS?

We'll start with basic HTML and CSS (assuming you can build a blank HTML document and link a stylesheet to it).

<div class="img-circular"></div>
Copy after login

Let's set a basic style for the class img-circular.

.img-circular{
 width: 200px;
 height: 200px;
 background-image: url(&#39;img/tupian.jpg&#39;);
 background-size: cover;
 display: block;
}
Copy after login

The background -size in the above code is a new property of CSS3, which can be used to manipulate the size of the background. You can set its width and height by entering exact pixel values, percentages, or make a background cover to fit the entire page.

After we set up the image, let’s change the CSS code to create a circular frame. We'll use the border-radius property, which allows us to change the arc of an element's corners. To make the image circular, our CSS file now looks like this:

.img-circular{
 width: 200px;
 height: 200px;
 background-image: url(&#39;img/tupian.jpg&#39;);
 background-size: cover;
 display: block;
 border-radius: 100px;
 -webkit-border-radius: 100px;
 -moz-border-radius: 100px;
}
Copy after login

The result is as follows: The picture becomes circular

How to implement a circular image using pure CSS?

This article is all over here. For more exciting content, you can pay attention to the CSS Video Tutorial column on the PHP Chinese website! ! !

The above is the detailed content of How to implement a circular image using pure CSS?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
css
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template