Assume there is such an initial code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div { margin-left: 100px; margin-top: 100px; padding: 0; width: 200px; height: 200px; background-color: green; outline: 20px solid #000; outline-offset: 10px; } </style> </head> <body> <div></div> </body> </html> The effects are as follows: Then change the value of the outline-offset property to -118px, and the border will become a plus sign. Of course, in order to make the effect more significant, I added an animation effect to show it, as shown in the following code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> div { margin-left: 100px; margin-top: 100px; padding: 0; width: 200px; height: 200px; background-color: green; outline: 20px solid #000; animation: move 3s infinite; } @keyframes move { 0% { outline-offset: 10px; } 100% { outline-offset: -118px; } } </style> </head> <body> <div></div> </body> </html> The effects are as follows: Use outline-offset to make a plus sign summary I find this very interesting. I tried it many times here. Here I summarize the conditions for using negative values of the outline-offset property:
After this example, I thought again that there are many CSS properties and places where they can take negative values, and there are also many unexpected effects. The most well-known one is negative margin. Using negative margin, you can achieve similar multi-column equal height layout, vertical centering, etc. Are there any other interesting techniques for using negative values? The following article introduces some interesting usage scenarios of CSS negative values. Use scale(-1) to achieve flip Usually, if we want to achieve a 180° flip of an element, we will use <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .g_container { position: absolute; margin: 100px 0 0 500px; } .item { width: 100px; height: 100px; background-color: green; position: relative; border-radius: 50%; } .item { transform: rotate(0) translate(-80px, 0) ; } .item:nth-child(1) { animation: rotate 3s infinite linear; } .item:nth-child(2) { animation: rotate 3s infinite 1s linear; } .item:nth-child(3) { animation: rotate 3s infinite 2s linear; } @keyframes rotate { 100% { transform: rotate(360deg) translate(-80px, 0) ; } } </style> </head> <body> <div class="g_container"> <div class="item"></div> <div class="item"></div> <div class="item"></div> </div> </body> </html> See the effect: Of course, if you want to make the three balls move at the same time and remove the delay, you can change the code to this: .item:nth-child(1) { animation: rotate 3s infinite linear; } .item:nth-child(2) { animation: rotate 3s infinite -1s linear; } .item:nth-child(3) { animation: rotate 3s infinite -2s linear; } I won't talk about the effect, it's just simultaneous movement, you can refer to the effect above Negative margin Negative margin is widely used in CSS. The margin of an element can be set to a negative value. Before the flexbox layout specification became popular, it still took some effort to achieve multi-line equal-height layout. One way is to use the method of canceling out positive padding and negative margin. There is a layout as follows: The contents of the left and right columns are uncertain, that is, highly unknown. But I hope that no matter there is more content on the left or on the right, the height of the two columns will always remain the same. OK, one hack is to use a large positive padding and the same negative margin to fill the left and right columns: .left { ... padding-bottom: 9999px; margin-bottom: -9999px; } .right { ... padding-bottom: 9999px; margin-bottom: -9999px; } It can be achieved that no matter how the height of the left and right columns changes, the lower column will change with the other column. To sum up In addition to these, there are many more properties, examples of which are not listed here (due to the author's limited level and time), for example:
Summarize This is the end of this article about using the outline-offset property in CSS to implement the plus sign. For more related CSS outline-offset property content, please search 123WORDPRESS.COM's previous articles or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! |
<<: Solution to the problem of saving format in HTML TextArea
>>: A brief discussion on how to use slots in Vue
1.watch listener Introducing watch import { ref, ...
Table of contents Preface 1.notnull 2. unique 3. ...
The computer system has been reinstalled, and the...
Seeing the recent popular WeChat tap function, I ...
The content involved in Web front-end development...
1. Alibaba Cloud selects the appropriate cloud se...
Firewall A firewall is a set of rules. When a pac...
Yesterday when I was implementing the function of...
Table of contents Uninstall and install samba Cre...
1. Enter the Docker official website First, go to...
This is a very simple pure CSS3 white cloud float...
1. Naming conventions 1. Database names, table na...
Async Hooks is a new feature of Node8. It provide...
Generally speaking, it is unlikely that you will ...
Record the installation and configuration method ...