50 lines of code to change 5 skin colors, including transparent I'll give you the code first, you can use it yourself. Just create an HTML file and paste it in to use it. You can't use it casually. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> #box{width: 100%;height:100%;background-color: red;position: absolute;top:0;left:0;right:0;bottom:0;} #box>div{float:right;width: 30px;height: 30px;margin:10px;border: 1px #333 solid;} #box1{background-color: red} #box2{background-color: yellow} #box3{background-color: blue} #box4{background-color: green} </style> </head> <body> <div id="box"> <div id="box1"></div> <div id="box2"></div> <div id="box3"></div> <div id="box4"></div> <div id="box5"></div> </div> </body> <script> var box = document.getElementById('box'); var box1 = document.getElementById('box1'); var box2 = document.getElementById('box2'); var box3 = document.getElementById('box3'); var box4 = document.getElementById('box4'); var box5 = document.getElementById('box5'); box1.onclick = function(){ box.style.backgroundColor = 'red'; } box2.onclick = function(){ box.style.backgroundColor = 'yellow'; } box3.onclick = function(){ box.style.backgroundColor = 'blue'; } box4.onclick = function(){ box.style.backgroundColor = 'green'; } box5.onclick = function(){ box.style.backgroundColor = 'transparent'; } </script> </html> The code is condensed and easy to understand. I won't talk about the basic HTML tags, let's talk about the text style under body first <body> <div id="box"> <div id="box1"></div> <div id="box2"></div> <div id="box3"></div> <div id="box4"></div> <div id="box5"></div> </div> </body> Finally, we will use JS. If we name it with "id" here, we can write less code later. This big red box is #box. I added a default color to it. If no color is added, it will be transparent. There is a difference between the first and fourth ones. The difference is that the color of the first one is transparent, while the color of the second one is red - the same as the base color. <style> #box{width: 400px; height: 400px;background-color: red;border: 1px #000 solid;} #box>div{float:right;width: 30px; height: 30px;margin:10px;border: 1px #333 solid;} #box1{background-color: red} #box2{background-color: yellow} #box3{background-color: blue} #box4{background-color: green} #box5{} </style> This is the Css style.
red is red; yellow is yellow; blue is blue; green is green var box = document.getElementById('box'); var box1 = document.getElementById('box1'); var box2 = document.getElementById('box2'); var box3 = document.getElementById('box3'); var box4 = document.getElementById('box4'); var box5 = document.getElementById('box5'); This is a DOM selector that selects each box individually for easier understanding. If you want to check all the boxes, box1.onclick = function(){ box.style.backgroundColor = 'red'; } The meaning of this sentence is: It’s the last one—the little red square.
When box1 is onclicked, box will function(){} This is easy to understand, so let's take a look at what is inside function(){}
Final: box.style.backgroundColor = 'transparent'; The transparent in here is the default value of the background color. Writing it like this means restoring its original appearance, which is transparent. Summarize This is the end of this article about the implementation code of the front-end html skin changing function. For more relevant front-end html skin changing content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! |
<<: CSS position fixed left and right double positioning implementation code
>>: How to hide elements on the Web and their advantages and disadvantages
1. The proxy_pass directive of the 1.ngx_stream_p...
1. Prerequisites Since I have installed it severa...
Table of contents 1. setState() Description 1.1 U...
I recently wrote a script for uploading multiple ...
1. The error information reported when running th...
Problem description: After the front-end deletes ...
This question is very strange, so I will go strai...
This article records the installation tutorial of...
Method 1: Use the target event attribute of the E...
Table of contents 1 element offset series 1.1 Off...
Table of contents 1. Use closures 2. Use ES6 clas...
Table of contents Preface 1. The database name or...
When Mysql associates two tables, an error messag...
Table of contents Preface What are dynamic proper...
This article is mainly to let beginners understan...