The border-radius in CSS3 can be easily used to draw arcs. If it is only used to make rounded rectangles, it would be too wasteful. Here is an example of using the border-radius of CSS3 to draw Tai Chi and love patterns. , Friends who need it can refer to
太极图
border-radius. In addition to creating a border and rounded corner effect, if you use it in drawing illustrations, it can actually produce an effect. So many different ideas. The author will continue to use it to teach you how to draw Tai Chi pictures today.
View source code HTML
<body> <p class="taichi"> <p class="white-circle"></p> <p class="black-circle"></p> </p> </body>
Because there is a black and a white circle in the Tai Chi diagram, two more p's are placed in the block.
Please open your eyes and look carefully. I will first divide the large block into one white and one black:
View source code CSS
.taichi { position: relative; width: 48px; /* 50 - 2 */ height: 96px; /* 100 - 2 - 2 */ background: #fff; border: 2px solid #000; border-width: 2px 50px 2px 2px; border-radius: 50%; }
General box mode (Box Model) is calculated together with the width and height of the block together with the border width, so we want to make a block with a width and height of 100×100, but if the border width is 2px, then the part inside should be only 96px . What’s special is that the author directly sets the width of the right border to 50px, so the width inside the block only needs 48px.
When this is set and the border-radius rounded corner effect is added, it will become~
Hehe~There is already one black and one white block. , then add a white circle first:
View source code CSS
.white-circle { position: absolute; top: 0; left: 50%; background: #fff; border-radius: 50%; width: 48px; height: 48px; }
Here is to directly generate a complete white circle and place it in the middle of the upper half:
The black circle is placed in the lower half:
View the source code CSS
.black-circle { position: absolute; top: 50%; left: 50%; background: #000; border-radius: 50%; width: 48px; height: 48px; }
It looks like there are already 9 images~
Finally, there are still two small dots of opposite colors in these two circles. For these two small dots, we only need to use ::after pseudo-elements (Pseudo-elements). That’s it:
View source code CSS
.white-circle::after { content: ""; position: absolute; top: 17px; /* (50-16)/2 */ left: 17px; /* (50-16)/2 */ background: #000; border-radius: 50%; width: 16px; height: 16px; } .black-circle::after { content: ""; position: absolute; top: 17px; /* (50-16)/2 */ left: 17px; /* (50-16)/2 */ background: #fff; border-radius: 50%; width: 16px; height: 16px; }
Will~ Isn’t it amazing! ?
爱
The above teaches you how to use border-radius to draw Tai Chi diagrams, and the following will teach you how to use the rounded corner effect as well. Love.
We only need a p block:
<body> <p class="heart"></p> </body>
Then specify the width and height of the block:
View source code CSS
.heart { position: relative; width: 140px; height: 115px; }
The heart is divided into the left and right blocks, and the ::before pseudo-elements (Pseudo-elements) are used to generate the left block:
View the source code CSS
.heart::before { content: ""; position: absolute; left: 70px; top: 0; width: 70px; height: 115px; background: red; border-radius: 50px 50px 0 0; }
Because only the rounded corners on the upper left and upper right are set, it becomes a round-headed pillar:
Then I need to change its rotation center point to move it towards Rotate left 45 degrees:
View source code CSS
.heart::before { content: ""; position: absolute; left: 70px; top: 0; width: 70px; height: 115px; background: red; border-radius: 50px 50px 0 0; -webkit-transform: rotate(-45deg); -moz-transform: rotate(-45deg); -o-transform: rotate(-45deg); transform: rotate(-45deg); -webkit-transform-origin: left bottombottom; -moz-transform-origin: left bottombottom; -o-transform-origin: left bottombottom; transform-origin: left bottombottom; }
transform-origin can change the center point of the element. Like background-position, it accepts two values, the first is to set the horizontal value, and the second is to set the vertical value. The default is center center, now I change it to the lower left:
The right part is the same, but only the rotation center point is changed to the lower right , and rotate to the right:
View source code CSS
.heart::after { content: ""; position: absolute; top: 0; left: 0; width: 70px; height: 115px; background: red; border-radius: 50px 50px 0 0; -webkit-transform: rotate(45deg); -moz-transform: rotate(45deg); -o-transform: rotate(45deg); transform: rotate(45deg); -webkit-transform-origin: rightright bottombottom; -moz-transform-origin: rightright bottombottom; -o-transform-origin: rightright bottombottom; transform-origin: rightright bottombottom; }
When both sides are generated, a bright red heart will appear:
What~ Mr. Zhong from Zhonghe asked why he couldn't move... It doesn't matter, add an animation animation effect to it:
View source code CSS
.heart { -webkit-animation: jump 1s infinite ease-out; -moz-animation: jump 1s infinite ease-out; -o-animation: jump 1s infinite ease-out; animation: jump 1s infinite ease-out; } @-webkit-keyframes jump { 0%, 60%, 75%, 90%, 100% { -webkit-transform: scale(1); } 15% { -webkit-transform: scale(0.6); } 30% { -webkit-transform: scale(1); } 45% { -webkit-transform: scale(0.7); } } @-moz-keyframes jump { 0%, 60%, 75%, 90%, 100% { -moz-transform: scale(1); } 15% { -moz-transform: scale(0.6); } 30% { -moz-transform: scale(1); } 45% { -moz-transform: scale(0.7); } } @-o-keyframes jump { 0%, 60%, 75%, 90%, 100% { -o-transform: scale(1); } 15% { -o-transform: scale(0.6); } 30% { -o-transform: scale(1); } 45% { -o-transform: scale(0.7); } } @keyframes jump { 0%, 60%, 75%, 90%, 100% { transform: scale(1); } 15% { transform: scale(0.6); } 30% { transform: scale(1); } 45% { transform: scale(0.7); } }
Through Use transform's scale(x, y) to change the size of the heart, so that the entire animation looks like a popping jump:
The above is the entire article Content, I hope it will be helpful to everyone’s learning. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
About the use of window units and percentage units in CSS
How to implement custom "W" in CSS3 "Shaped running trajectory
Use CSS3 to achieve the flashing effect of text looping to the right
The above is the detailed content of Use CSS3 border-radius to draw Tai Chi and love patterns. For more information, please follow other related articles on the PHP Chinese website!