Home >Web Front-end >HTML Tutorial >How to comment in code and what are its benefits
In the code, you can use the Ctrl / shortcut key to comment the code, which helps us understand the code, speed up the development process and maintain code consistency
When we One thing you usually learn when learning HTML or CSS is how to write comments in your code. However, many developers still don't use annotations to their advantage. Today we will introduce how to use comments extensively in HTML and CSS to improve our workflow.
【Recommended course: HTML Tutorial】
##Importance of comments:
If we are doing an independent project, or are the only developer to review the code we have written, then we can Write code according to your own ideas. But if you are working with others, if the code does not have any comments, it will be difficult for others to understand and understand the meaning of the code. This will increase the burden of cooperation on the developers, but having comments will greatly reduce the burden.Benefits of learning to comment:
(1) Helps maintain consistency (2) Helps understand (3) Help with patches or quick fixes(4) Help speed up the development process(5) Help improve collaboration efficiencyNote :
Be careful not to write too long when commenting on the code. This will increase the redundancy of the code and avoid spending a lot of time writing unimportant comments.How to comment in the code
(1) In the HTML code:<body> <!--HTML代码--> <div>hello world!</div> </body>To comment the code in HTML, just add 22762515966677434da64d3f498feb31 That’s it, we can use the shortcut key Ctrl / to complete (2) In the CSS code:
<style> div{ width:100px; height:30px; border:1px solid #ccc; /*设置字体垂直居中*/ text-align: center; line-height: 30px; } </style>The comment in CSS is /**/ , the shortcut key is Ctrl / (3)
<script type="text/javascript"> // 点击div时改变其背景颜色 var div=document.getElementsByTagName("div")[0]; div.onclick=function(){ div.style.backgroundColor="pink" } </script>in JavaScript code, the comment in JavaScript is //, the shortcut key is Ctrl /Rendering Before clicking: After clicking:
The above is the detailed content of How to comment in code and what are its benefits. For more information, please follow other related articles on the PHP Chinese website!