Conceptual confusion about parsing of HTML by browsers and HTML's form (syntactical) -


someone trying harass , demean me today challenging knowledge of html in general never claimed have have begun learning it. asked me following 2 questions:

question 1. if create html page string in without writing html markups in (no body, no html, no doctype), why browser still render , display string if it's paragraph?

to this, used best guess browser still manages display paragraph because that's best guess , makes missing tags assuming that's author had wanted , "put" tags if never manually wrote it.

question 2. in above example, if write several strings in different lines in html's source code, browser still displays them single line of text.

again, used best guess , concluded html free form language , won't care how many spaces or indentations there in source code.

however, didn't seem pleased. answers wrong? if yes, wrong or partially , correct answers these questions?

thanks reading , being patient description.

question 1. if create html page string in without writing html markups in (no body, no html, no doctype), why browser still render , display string if it's paragraph?

to this, used best guess browser still manages display paragraph because that's best guess , makes missing tags assuming that's author had wanted , "put" tags if never manually wrote it.

since, in both cases, <!doctype ...> not used, not found in last step in initial insertion mode, , therefore entire document rendered in quirks mode.

while browsers (at least firefox , chrome) don't parse paragraph, do render simple string same paragraph in quirks mode default. due fact "when document in quirks mode, vertical margins on html elements @ top or bottom of body elements expected collapsed zero" (source, more on collapsing margins), margin-top of body consumes margin-top of p. since simple string doesn't have margin, nothing happens. end result both paragraph of text , text displayed same.

this how browser handles simple string. pay special attention dom view, shows final structure of document is. comparison, see what paragraph looks like. while may appear same in rendering, structure not same.

now, illustrate point collapsing margins, wrap content (text or paragraph) div has border see uncollapsed margins. this how browser handles plain text, while this how browser handles paragraph.

however, <!doctype ...> included (to prevent browser entering quirks mode), plain text document not appear same document paragraph (the margin-top of p element doesn't collapse margin-top of body element).

question 2. in above example, if write several strings in different lines in html's source code, browser still displays them single line of text.

again, used best guess , concluded html free form language , won't care how many spaces or indentations there in source code.

html treats whitespace (unless white-space set other normal) single space (collapsed). ergo, test\n\ntest equivalent test test.

however, didn't seem pleased. answers wrong? if yes, wrong or partially , correct answers these questions?

your conclusions correct, don't handle edge cases (e.g. if browser changes font/color/etc of p element).


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -