-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathf4.html
205 lines (169 loc) · 7.79 KB
/
f4.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>HTML - Comments</title>
<link rel="shortcut icon" sizes="200*200" type="image/x-icon" href="logo1.jpg"></head>
<body style="background-color: aliceblue;color:rgb(90, 46, 194)">
<h1>HTML - Comments</h1>
<div class="clearer"></div>
<p>Comment is a piece of code which is ignored by any web browser. It is a good practice to add comments into your HTML code, especially in complex documents, to indicate sections of a document, and any other notes to anyone looking at the code. Comments help you and others understand your code and increases code readability.</p>
<p>HTML comments are placed in between <b><!-- ... --></b> tags. So, any content placed with-in <!-- ... --> tags will be treated as comment and will be completely ignored by the browser.</p>
<h3>Example</h3>
<pre style="background-color:azure; class="prettyprint notranslate">
<!DOCTYPE html>
<html>
<head> <!-- Document Header Starts -->
<title>This is document title</title>
</head> <!-- Document Header Ends -->
<body>
<p>Document content goes here.....</p>
</body>
</html>
</pre>
</div>
<a target="_blank" href="f4-1.html" class="w3-btn w3-margin-bottom"><button style="background-color:rgb(115, 126, 226);">Try it Yourself</button> »</a>
</div>
<h2>Valid vs Invalid Comments</h2>
<p>Comments do not nest which means a comment cannot be put inside another comment. Second the double-dash sequence "--" may not appear inside a comment except as part of the closing --> tag. You must also make sure that there are no spaces in the start-of comment string.</p>
<h3>Example</h3>
<p>Here, the given comment is a valid comment and will be wiped off by the browser.</p>
<pre style="background-color:azure; class="prettyprint notranslate">
<!DOCTYPE html>
<html>
<head>
<title>Valid Comment Example</title>
</head>
<body>
<!-- This is valid comment -->
<p>Document content goes here.....</p>
</body>
</html>
</pre>
</div>
<a target="_blank" href="f4-2.html" class="w3-btn w3-margin-bottom"><button style="background-color:rgb(115, 126, 226);">Try it Yourself</button> »</a>
</div>
<p>But, following line is not a valid comment and will be displayed by the browser. This is because there is a space between the left angle bracket and the exclamation mark.</p>
<pre style="background-color:azure; class="prettyprint notranslate">
<!DOCTYPE html>
<html>
<head>
<title>Invalid Comment Example</title>
</head>
<body>
< !-- This is not a valid comment -->
<p>Document content goes here.....</p>
</body>
</html>
</pre>
</div>
<a target="_blank" href="f4-3.html" class="w3-btn w3-margin-bottom"><button style="background-color:rgb(115, 126, 226);">Try it Yourself</button> »</a>
</div>
<h2>Multiline Comments</h2>
<p>So far we have seen single line comments, but HTML supports multi-line comments as well.</p>
<p>You can comment multiple lines by the special beginning tag <!-- and ending tag --> placed before the first line and end of the last line as shown in the given example below.</p>
<h3>Example</h3>
<pre style="background-color:azure; class="prettyprint notranslate">
<!DOCTYPE html>
<html>
<head>
<title>Multiline Comments</title>
</head>
<body>
<!--
This is a multiline comment and it can
span through as many as lines you like.
-->
<p>Document content goes here.....</p>
</body>
</html>
</pre>
</div>
<a target="_blank" href="f4-4.html" class="w3-btn w3-margin-bottom"><button style="background-color:rgb(115, 126, 226);">Try it Yourself</button> »</a>
</div>
<h2>Conditional Comments</h2>
<p>Conditional comments only work in Internet Explorer (IE) on Windows but they are ignored by other browsers. They are supported from Explorer 5 onwards, and you can use them to give conditional instructions to different versions of IE.</p>
<h3>Example</h3>
<pre style="background-color:azure; class="prettyprint notranslate">
<!DOCTYPE html>
<html>
<head>
<title>Conditional Comments</title>
<!--[if IE 6]>
Special instructions for IE 6 here
<![endif]-->
</head>
<body>
<p>Document content goes here.....</p>
</body>
</html>
</pre>
<p>You will come across a situation where you will need to apply a different style sheet based on different versions of Internet Explorer, in such situation conditional comments will be helpful.</p>
</div>
<a target="_blank" href="f4-5.html" class="w3-btn w3-margin-bottom"><button style="background-color:rgb(115, 126, 226);">Try it Yourself</button> »</a>
</div>
<h2>Using Comment Tag</h2>
<p>There are few browsers that support <comment> tag to comment a part of HTML code.</p>
<blockquote><p><b>Note</b> − The <comment> tag deprecated in HTML5. Do not use this element.</p></blockquote>
<h3>Example</h3>
<pre style="background-color:azure; class="prettyprint notranslate">
<!DOCTYPE html>
<html>
<head>
<title>Using Comment Tag</title>
</head>
<body>
<p>This is <comment>not</comment> Internet Explorer.</p>
</body>
</html>
</pre>
</div>
<a target="_blank" href="f4-6.html" class="w3-btn w3-margin-bottom"><button style="background-color:rgb(115, 126, 226);">Try it Yourself</button> »</a>
</div>
<h2>Commenting Script Code</h2>
<p>Though you will learn JavaScript with HTML, in a separate tutorial, but here you must make a note that if you are using Java Script or VB Script in your HTML code then it is recommended to put that script code inside proper HTML comments so that old browsers can work properly.</p>
<h3>Example</h3>
<pre style="background-color:azure; class="prettyprint notranslate">
<!DOCTYPE html>
<html>
<head>
<title>Commenting Script Code</title>
<script>
<!--
document.write("Hello World!")
//-->
</script>
</head>
<body>
<p>Hello , World!</p>
</body>
</html>
</pre>
</div>
<a target="_blank" href="f4-7.html" class="w3-btn w3-margin-bottom"><button style="background-color:rgb(115, 126, 226);">Try it Yourself</button> »</a>
</div>
<h2>Commenting Style Sheets</h2>
<p>Though you will learn using style sheets with HTML in a separate tutorial, but here you must make a note that if you are using Cascading Style Sheet (CSS) in your HTML code then it is recommended to put that style sheet code inside proper HTML comments so that old browsers can work properly.</p>
<h3>Example</h3>
<pre style="background-color:azure; class="prettyprint notranslate">
<!DOCTYPE html>
<html>
<head>
<title>Commenting Style Sheets</title>
<style>
<!--
.example {
border:1px solid #4a7d49;
}
//-->
</style>
</head>
<body>
<div class = "example">Hello , World!</div>
</body>
</html>
</pre>
</div>
<a target="_blank" href="f4-8.html" class="w3-btn w3-margin-bottom"><button style="background-color:rgb(115, 126, 226);">Try it Yourself</button> »</a>
</div>
</body>
</html>