Achieve resultsRequirements/Functionality:How to draw a heart using CSS+HTML. analyze: A heart can be formed by combining a square and two circles. Add another circle. Finally, rotate the entire shape 45 degrees clockwise. Initial implementation:First draw a square: <body> <div id="heart"></div> </body> #heart{ height: 300px; width: 300px; border: 2px solid black; } Add a circle to the left of the square. Use the pseudo class: before to achieve this. #heart{ height: 200px; width: 200px; border: 2px solid black; position: relative; } #heart:before{ content: ''; width: 200px; height: 200px; border: 2px solid black; border-radius: 50%; // Square with rounded corners becomes a circle position: absolute; left: -100px; // shift the square half its length to the left} The graph now looks like this: Add another circle, here we use the after pseudo class to achieve it. #heart{ height: 200px; width: 200px; border: 2px solid black; position: relative; } // I'm being lazy here. I'll just write one block #heart:before, #heart:after { content: ''; width: 200px; height: 200px; border: 2px solid black; border-radius: 50%; position: absolute; left: -100px; } // For the second circle, we only need to move the square halfway up#heart:after{ left: 0; top: -100px; } The last step is to rotate it and then add some color. Remove the border that was added to make it clearer. /*Rotate the heart and add color*/ transform: rotate(45deg); background-color: red; Complete code: <style> body,html{ display: flex; align-items: center; justify-content: center; height: 100vh; } #heart{ height: 200px; width: 200px; /*border: 2px solid black;*/ position: relative; transform: rotate(45deg); background-color: red; } #heart:before,#heart:after{ content: ''; width: 200px; height: 200px; /*border: 2px solid black;*/ border-radius: 50%; position: absolute; left: -100px; background-color: red; } #heart:after{ left: 0; top: -100px; } </style> </head> <body> <div id="heart"></div> </body> Summarize:A heart can be made up of a square and two circles. Here, we use the before and after pseudo-classes, and then shift the two pseudo-classes respectively. Finally, we add color to create a heart ❤️. The above is the detailed content of how to draw a heart with CSS3. For more information about drawing a heart with CSS3, please pay attention to other related articles on 123WORDPRESS.COM! |
<<: HTML solves the problem of invalid table width setting
1. Unzip mysql-8.0.21-winx64 2. Configure environ...
This article will introduce how to save IP addres...
Brief Description This is a CSS3 cool 3D cube pre...
Nine simple examples analyze the use of HTML form...
Table of contents Preface 1. Basic Data 2. Inheri...
After reading some articles, I finally figured ou...
The so-called favicon, which is the abbreviation o...
Redis uses the apline (Alps) image of Redis versi...
<META http-equiv="Page-Enter" CONTENT...
This article example shares the specific code of ...
The reason is that it was not uninstalled cleanly...
What is a table? It is composed of cell cells. In...
This tutorial is only applicable to Windows syste...
A brief introduction to protobuf Protobuf is Goog...
This article example shares the specific code of ...