Use Border-radius to draw circles and put words in the center of a word

Source: Internet
Author: User

Requirements: Use HTML to draw a circle, a word in the circle to describe it, and to center the word.

Analysis: First draw a circle, my first idea is to use pictures, and was scolded a meal, and then think to use canvas painting, and was scolded a meal, this just noticed that CSS exists a property Border-radius.

Border-radius was used to add rounded corners to the div, *px or percent, and this value refers to the radius of the fillet (imagine, rounded corners, it must be centered on a point, a point for the radius of the painting, and at Four corners, with a radius, in fact, no longer need to specify the center of the circle). So to extend it, if the specified parameter value is greater than or equal to the width of the Div, then the thing drawn should be a circle.

Try this:

<!doctype html>

The effect chart is as follows:

OK, now that we've got a circle, and the circle is right in the center of the screen (the code looks at it), how do you add words to the circle? Perhaps the most direct way is to write directly inside the div, by using Text-align to center the text, but at this time is not at the center of the circle, but only in the center of the document flow, then how to position the word in the center of the circle, in other words, how to vertically centered.

The answer is to use line-height,line-height simply to set the line height. Because the row height is exactly the size of the font in the original document stream, what happens if the row height is set to the height of the entire circle. Naturally, the font will be at the center of the line, so that the vertical center is achieved.

The code is as follows:

Text-align:center;
line-height:300px;
font-size:30px;

There is also an interesting problem, we set the diameter of the circle is 300px, the actual picture is not the diameter of 300px, you know why.

Reference Links:
Write link content here
Write link content here

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.