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.

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,088评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,715评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,361评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,099评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 60,987评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,063评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,486评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,175评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,440评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,518评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,305评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,190评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,550评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,880评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,152评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,451评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,637评论 2 335

推荐阅读更多精彩内容