HTML 面試題

  1. Inline-level element vs. Block-level element
    Inline-level elements: It occupies only the space bounded by the tags that define the inline element. (eg. <span>,<a>,<img>,<td>)
    Block-level elements: It occupies the entire space of its parent element(container), thereby creating a "block". (eg. <div>, <p>,<form>,<h1>,<ul>)

  2. HTML5 quirks mode
    Little history: In the old days of the web, pages were written in two versions: one for IE, the other for Netscape Navigator. When the web standards were made at W3C, browsers could not directly start using them, as doing so would break most existing sites on the web. Browsers therefore introduced two modes to treat new standards compliant sites differently from old legacy sites, which are the quirks mode and almost standard mode.

    Quirks Mode: the layout emulates nonstandard behavior in Navigator4 and IE5 to support the websites that were built before the widespread adoption of web standards.

  3. DOCTYPE
    <!DOCTYPE> must be the very first thing in HTML document, before <html> tag. It is not a html tag, it is an instruction to inform the browser which version of HTML the page is written in.

  4. Cache Buster
    Purpose: Cache-buster is a unique piece of code that prevents a browser from reusing an ad it has already seen and cached, or saved, to a temporary memory file.

    How it is accomplished: It uses random number inserted into the ad tag on each page load. The random number makes every ad call look unique to the browser and therefore prevents it from associating the tag with a cached file, forcing a new call to the ad server.

    Reasons behind the technique: Cache can directly speed up the website, since it will not need to interact with server and download the content. However, for the ad on the webpage, the publisher get paid for every impression, they would prefer the browser does not use the cached ad on the hard drive. Also, the cache can mess with ads' reports and ROI calculation.

  5. px, pt AND em
    px(Pixels): the absolute size that you would see on your screen.
    pt(Points): 1pt is equal to 1/72 inch. Fixed size unit.
    em(Ems): refers to the base text size more like percentage. 1em means the same thing as a value of 100 percent.
    vh,vw(view): they are associate with the whole viewport of the browser and act as the percentage of the current viewport width and height.

  1. div
    A block level element that can be used as a container for grouping other HTML elements.

  2. span
    An inline element that can be used as a container for text.

  3. HTML Form
    It is used to select different kinds of user input, pass data to a server.

  4. iFrame
    It is used to display a webpage within a webpage. Can be a target for a link.

  5. canvas
    It is used to draw graphics, on the fly, via scripting. It is only a container for graphics. Pixel-based.

  6. SVG(Scalable Vector Graphics)
    It is used to define graphics for the web. It is a language for describing 2D graphics in XML. Every element is available within the SVG DOM, can easily interact with. Best suited for applications with large rendering areas.
    Advantages: (1). SVG images can be searched, indexed, scripted and compressed
    (2). SVG images are scalable
    (3). SVG images can be printed with high quality at any resolution
    Disadvantages: Slow redering if complex(Use DOM a lot will be slow), not suited for game application

  7. HTML local storage
    local storage: store user data(large data storage), no expiration date
    session storage: store user data, gets cleared when session ends--browser closed.
    cookie: store password, username, searched words(small text files on computer)

  8. Web worker
    It is a JavaScript that runs in the background, independently of other scripts, without affecting the performance of the page. You can continue to interact with the web page while it runs in the background.

  9. Display something with right spacing and line-breaks
    <pre>: represents preformatted text. It will show the text as it was typed in with spacing and new lines.

  10. label
    It provides a usability improvement for mouse users, because if the user clicks on the text within the label element, it toggles the control.

  11. To group a list of radio-buttons:
    All the radio-buttons should share the same name in order to extract the value from the script.

  12. Elements and New attrbiutes for <input> in HTML5:
    New semantic element: <header> <footer> <article> <section>
    New form controls like number, date, time, calendar
    New graphic elements: <svg> <canvas>
    New multimedia elements: <audio> <video>

  13. Object element
    It defines an embedded object within an HTML document. It is used to embed plug-ins(audio, video, PDF readers, Flash Players) in web pages.

  14. Application Cache
    It caches web application and accessible without an internet connection.
    Advantages: Offline Browsing, Speed, Reduced Server Load
    Disadvantages: (1). Update one file will cause the whole application to be downloaded again.
    (2). Browser will use this version until the manifest has been changed
    (3). Unreliable JavaScript API
    (4). IE 10 forbids the application cache

  15. Enable application cache
    Include the manifest attribute in the document's html tag:
    <!DOCTYPE html>
    <html manifest="demo.appcache">
    ...
    </html>
    demo.appcache is a text file which contains all the files the browser should cache for the application.

  16. Cache and Cookie differences:
    (1). Different Purposes:
    Cookie is made to store information to track different characteristics related to user like the user preferences, user name, passwords etc.
    Cache is made to load the web pages faster(instead of loading from the server), typically keep the resource file like audio, video or flash files
    (2). Different Life Cycle:
    Cookie expires after some time
    Cache exists on the hard drive until manually removed

  17. Geolocation API
    HTML Geolocation API is used to get the geographical position of a user.(Not available until the user approves it)

  18. HTML Plug-in
    It extends the functionality of the HTML browser(usually use the object tag or the embed tag)

  19. HTML5 custom attribute
    Custom attributes are used to store custom data private to the page or application, for which there are no appropriate attributes or elements to describe in native HTML5.
    Custom data attributes can easily associate some scripting data with the elements without having to insert inline javascript all over the place.

    A custom attribute has two parts: name=value, eg. <div id="a" data-fruit="12"></div>. The name of the attribute must not contain any uppercase letter. It should start with a prefix:"data-". The value can be any string.
    With JS, you can extract the attribute:
    var plant = document.getElementId("a");
    var fruitCount = plant.getAttribute("data-fruit");

  20. HTML5 custom elements:
    Allow users to define new types of HTML elements. Elements are created using document.registerElement():
    var x_element = document.registerElement("x-element");
    document.body.appendChild(new x_element);
    The element name must contain a dash. This allows the parser to distinguish custom elements form regular elements but also ensures forward compatibilty when new tags are added to HTML.
    document.registerElement() has an optional argument to describe the prototype of the element.

  21. Convert the HTMl to XHTML
    XHTML is HTML4 written as an XML application.(Extensible Hypertext Markup Language)
    (1). Add XHTML doctype to the first line of every page
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    (2). Add an xmlns attribute to the html element of every page
    (3). Change all element names to lowercase
    (4). Close all empty elements
    (5). Change all attribute names to lowercase
    (6). Quote all attribute values

    XML and HTML difference:
    Different on purposes: XML describes data with focus on what data is.
    HTML was designed to display data with focus on how data looks.

  22. HTML5 microdata
    The Microdata spec provides a standardized syntax for additional semantic markup to your web pages to enhance the machine readability of your web pages.
    ?
    Microdata defines five HTML attributes that can be applied to any HTML5 tag. Most developers will only ever use itemscope, itemtype and itemprop. Itemref and itemid aren’t necessary to get up and running with microdata and aren’t needed by the most common formats.
    Itemscope - Indicates the element is a microdata element and its child elements are part of its microdata format.
    Itemtype - Defines the vocabulary to be used by the microdata format.
    Itemid - The unique identifier of the item, if defined by the microdata vocabulary.
    Itemprop - An individual data element.
    Itemref - Allows a microdata element to reference another element on the page to define it by either HTML id or by itemid.

  1. DHTML(Dynamic HTML)
    DHTML is a collection of technologies used to move beyond the static presentation of information to create more interactive web pages. Technologies like JS, CSS, DOM play a role in the DHTML.

29.Progressive rendering is the name given to techniques used to render content for display as quickly as possible.

It used to be much more prevalent in the days before broadband internet but it's still useful in modern development as mobile data connections are becoming increasingly popular (and unreliable!)

Examples of such techniques :

Lazy loading of images where (typically) some javascript will load an image when it comes into the browsers viewport instead of loading all images at page load.
Prioritizing visible content (or above the fold rendering) where you include only the minimum css/content/scripts necessary for the amount of page that would be rendered in the users browser first to display as quickly as possible, you can then use deferred javascript (domready/load) to load in other resources and content.

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末章鲤,一起剝皮案震驚了整個濱河市套像,隨后出現(xiàn)的幾起案子鳖眼,更是在濱河造成了極大的恐慌置蜀,老刑警劉巖,帶你破解...
    沈念sama閱讀 210,914評論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件敦间,死亡現(xiàn)場離奇詭異凛捏,居然都是意外死亡,警方通過查閱死者的電腦和手機馁启,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 89,935評論 2 383
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來芍秆,“玉大人惯疙,你說我怎么就攤上這事±颂” “怎么了螟碎?”我有些...
    開封第一講書人閱讀 156,531評論 0 345
  • 文/不壞的土叔 我叫張陵,是天一觀的道長迹栓。 經(jīng)常有香客問我,道長俭缓,這世上最難降的妖魔是什么克伊? 我笑而不...
    開封第一講書人閱讀 56,309評論 1 282
  • 正文 為了忘掉前任,我火速辦了婚禮华坦,結(jié)果婚禮上愿吹,老公的妹妹穿的比我還像新娘。我一直安慰自己惜姐,他們只是感情好犁跪,可當我...
    茶點故事閱讀 65,381評論 5 384
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著歹袁,像睡著了一般坷衍。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上条舔,一...
    開封第一講書人閱讀 49,730評論 1 289
  • 那天枫耳,我揣著相機與錄音,去河邊找鬼孟抗。 笑死迁杨,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的凄硼。 我是一名探鬼主播铅协,決...
    沈念sama閱讀 38,882評論 3 404
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼摊沉!你這毒婦竟也來了狐史?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,643評論 0 266
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎预皇,沒想到半個月后侈玄,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,095評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡吟温,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,448評論 2 325
  • 正文 我和宋清朗相戀三年序仙,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片鲁豪。...
    茶點故事閱讀 38,566評論 1 339
  • 序言:一個原本活蹦亂跳的男人離奇死亡汹忠,死狀恐怖框往,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤泽裳,帶...
    沈念sama閱讀 34,253評論 4 328
  • 正文 年R本政府宣布,位于F島的核電站齐佳,受9級特大地震影響锭弊,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜柜裸,卻給世界環(huán)境...
    茶點故事閱讀 39,829評論 3 312
  • 文/蒙蒙 一缕陕、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧疙挺,春花似錦扛邑、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,715評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至搀暑,卻和暖如春沥阳,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背险掀。 一陣腳步聲響...
    開封第一講書人閱讀 31,945評論 1 264
  • 我被黑心中介騙來泰國打工沪袭, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人樟氢。 一個月前我還...
    沈念sama閱讀 46,248評論 2 360
  • 正文 我出身青樓冈绊,卻偏偏與公主長得像,于是被迫代替她去往敵國和親埠啃。 傳聞我的和親對象是個殘疾皇子死宣,可洞房花燭夜當晚...
    茶點故事閱讀 43,440評論 2 348

推薦閱讀更多精彩內(nèi)容