Front-end development interview summary HTML, CSS part

Key points: understanding of web standards, browser differences, basic CSS skills: layout, box model, selector priority and usage, HTML5, CSS3, mobile development techniques, etc.

1. What does Doctype do? Strict mode and promiscuous mode - how to trigger these two modes and what is the meaning of distinguishing them?

    (1)、<!DOCTYPE> 声明位于文档中的最前面,处于 <html> 标签之前。告知浏览器的解析器,用什么文档类型 规范来解析这个文档。 

    (2)、严格模式的排版和 JS 运作模式是  以该浏览器支持的最高标准运行。

    (3)、在混杂模式中,页面以宽松的向后兼容的方式显示。模拟老式浏览器的行为以防止站点无法工作。

    (4)、DOCTYPE不存在或格式不正确会导致文档以混杂模式呈现。

2. What are the inline elements? What are block-level elements? What are the empty (void) elements?

(1)CSS规范规定,每个元素都有display属性,确定该元素的类型,每个元素都有默认的display值,比如div默认display属性值为“block”,成为“块级”元素;span默认display属性值为“inline”,是“行内”元素。  

(2)行内元素有:a b span img input select strong(强调的语气) 块级元素有:div ul ol li dl dt dd h1 h2 h3 h4…p  

(3)知名的空元素: <br> <hr> <img> <input> <link> <meta> 
     鲜为人知的是: <area> <base> <col> <command> <embed> <keygen> <param> <source> <track> <wbr>

3. CSS box model?

(1)两种, IE 盒子模型、标准 W3C 盒子模型;IE 的content部分包含了 border 和 pading;

(2)盒模型: 内容(content)、填充(padding)、边界(margin)、 边框(border).

4. What is the difference between link and @import?

    (1)、link属于XHTML标签,而@import是CSS提供的;

    (2)、页面被加载的时,link会同时被加载,而@import引用的CSS会等到页面被加载完再加载;

    (3)、import只在IE5以上才能识别,而link是XHTML标签,无兼容问题;

    (4)、link方式的样式的权重 高于@import的权重.

5. What are CSS selectors? Which properties can be inherited? How is the priority algorithm calculated? What are the new pseudo-classes in CSS3?

    *   1.id选择器( # myid)
        2.类选择器(.myclassname)
        3.标签选择器(div, h1, p)
        4.相邻选择器(h1 + p)
        5.子选择器(ul < li)
        6.后代选择器(li a)
        7.通配符选择器( * )
        8.属性选择器(a[rel = "external"])
        9.伪类选择器(a: hover, li: nth - child)

    *   可继承: font-size font-family color, UL LI DL DD DT;

    *   不可继承 :border padding margin width height ;

    *   优先级就近原则,样式定义最近者为准;

    *   载入样式以最后载入的定位为准;

The priority is:

       !important >  id > class > tag  

       important 比 内联优先级高

Examples of new pseudo-classes in CSS3:

    p:first-of-type 选择属于其父元素的首个 <p> 元素的每个 <p> 元素。
    p:last-of-type  选择属于其父元素的最后 <p> 元素的每个 <p> 元素。
    p:only-of-type  选择属于其父元素唯一的 <p> 元素的每个 <p> 元素。
    p:only-child    选择属于其父元素的唯一子元素的每个 <p> 元素。
    p:nth-child(2)  选择属于其父元素的第二个子元素的每个 <p> 元素。
    :enabled、:disabled 控制表单控件的禁用状态。
    :checked,单选框或复选框被选中。

6. How to center a div, how to center a floating element?

  • Give the div a width, then add the margin:0 auto attribute

        div{
            width:200px;
            margin:0 auto;
         }  
    
  • Center a floated element

          确定容器的宽高 宽500 高 300 的层
          设置层的外边距
    
         .div { 
          Width:500px ; height:300px;//高度可以不设
          Margin: -150px 0 0 -250px;
          position:relative;相对定位
          background-color:pink;//方便看效果
          left:50%;
          top:50%;
        } 
    

7. What is the core of the browser? What are the compatibility of the frequently encountered browsers? The reason, what is the solution, and commonly used hacking techniques?

    * IE浏览器的内核Trident、 Mozilla的Gecko、google的WebKit、Opera内核Presto;

    * png24为的图片在iE6浏览器上出现背景,解决方案是做成PNG8.

    * 浏览器默认的margin和padding不同。解决方案是加一个全局的*{margin:0;padding:0;}来统一。

    * IE6双边距bug:块属性标签float后,又有横行的margin情况下,在ie6显示margin比设置的大。 

      浮动ie产生的双倍距离 #box{ float:left; width:10px; margin:0 0 0 100px;} 

     这种情况之下IE会产生20px的距离,解决方案是在float的标签样式控制中加入 ——_display:inline;将其转化为行内属性。(_这个符号只有ie6会识别)

      渐进识别的方式,从总体中逐渐排除局部。 

      首先,巧妙的使用“\9”这一标记,将IE游览器从所有情况中分离出来。 
      接着,再次使用“+”将IE8和IE7、IE6分离开来,这样IE8已经独立识别。

      css
          .bb{
           background-color:#f1ee18;/*所有识别*/
          .background-color:#00deff\9; /*IE6、7、8识别*/
          +background-color:#a200ff;/*IE6、7识别*/
          _background-color:#1e0bd1;/*IE6识别*/

          } 

    *  IE下,可以使用获取常规属性的方法来获取自定义属性,
       也可以使用getAttribute()获取自定义属性;
       Firefox下,只能使用getAttribute()获取自定义属性. 
       解决方法:统一通过getAttribute()获取自定义属性.

    *  IE下,even对象有x,y属性,但是没有pageX,pageY属性; 
      Firefox下,event对象有pageX,pageY属性,但是没有x,y属性.

    * (条件注释)缺点是在IE浏览器下可能会增加额外的HTTP请求数。

    * Chrome 中文界面下默认会将小于 12px 的文本强制按照 12px 显示, 可通过加入 CSS 属性 -webkit-text-size-adjust: none; 解决.

    超链接访问过后hover样式就不出现了 被点击访问过的超链接样式不在具有hover和active了解决方法是改变CSS属性的排列顺序:
    L-V-H-A :  a:link {} a:visited {} a:hover {} a:active {}

8. What are the new features of html5\CSS3 and which elements have been removed? How to handle browser compatibility issues with HTML5 new tabs? How to differentiate HTML and HTML5?

  • HTML5 is now not a subset of SGML, it's mostly about the addition of images, location, storage, geolocation, etc.

    * 绘画 canvas 元素
    
      用于媒介回放的 video 和 audio 元素
    
      本地离线存储 localStorage 长期存储数据,浏览器关闭后数据不丢失;
      sessionStorage 的数据在浏览器关闭后自动删除
    
      语意化更好的内容元素,比如 article、footer、header、nav、section
    
      表单控件,calendar、date、time、email、url、search
    
      CSS3实现圆角,阴影,对文字加特效,增加了更多的CSS选择器  多背景 rgba
    
      新的技术webworker, websockt, Geolocation
    
  • removed element

    纯表现的元素:basefont,big,center,font, s,strike,tt,u;
    
    对可用性产生负面影响的元素:frame,frameset,noframes;
    
    * 是IE8/IE7/IE6支持通过document.createElement方法产生的标签,
      可以利用这一特性让这些浏览器支持HTML5新标签,
    
      浏览器支持新标签后,还需要添加标签默认的样式:
    
    * 当然最好的方式是直接使用成熟的框架、使用最多的是html5shim框架
       <!--[if lt IE 9]> 
       <script> src="http://html5shim.googlecode.com/svn/trunk/html5.js"</script> 
       <![endif]--> 
    

9. How do you implement the page design diagram, and how do you think the front end should complete the work with high quality? How to design a full-screen font layout?

* 首先划分成头部、body、脚部;。。。。。 

*  
  实现效果图是最基本的工作,精确到2px;

  与设计师,产品经理的沟通和项目的参与

  做好的页面结构,页面重构和用户体验

  处理hack,兼容、写出优美的代码格式

  针对服务器的优化、拥抱 HTML5。

10. What are the commonly used libraries? Common front-end development tools? What applications or components have been developed?

    * 使用率较高的框架有jQuery、YUI、Prototype、Dojo、Ext.js、Mootools等。尤其是jQuery,超过91%。

  轻量级框架有Modernizr、underscore.js、backbone.js、Raphael.js等。
 (理解这些框架的功能、性能、设计原理)

    * Sublime Text 、Eclipse、Notepad、Firebug、HttpWatch、Yslow。

    * 城市选择插件,汽车型号选择插件、幻灯片插件。弹出层。(写过开源程序,加载器,js引擎更好)
  1. JavaScript prototype, prototype chain? What are the characteristics?

    *  原型对象也是普通的对象,是对象一个自带隐式的 __proto__ 属性,原型也有可能有自己的原型,如果一个原型对象的原型不为null的话,我们就称之为原型链。
    *  原型链是由一些用来继承和共享属性的对象组成的(有限的)对象链。
    
    * JavaScript的数据对象有那些属性值?
    
      writable:这个属性的值是否可以改。
    
      configurable:这个属性的配置是否可以删除,修改。
    
      enumerable:这个属性是否能在for…in循环中遍历出来或在Object.keys中列举出来。
    
      value:属性值。
    
    * 当我们需要一个属性的时,Javascript引擎会先看当前对象中是否有这个属性, 如果没有的话,就会查找他的Prototype对象是否有这个属性。
    
     function clone(proto) {
    
      function Dummy() { }
    
      Dummy.prototype = proto;
    
      Dummy.prototype.constructor = Dummy;
    
      return new Dummy(); //等价于Object.create(Person);
    
     } 
    
            function object(old) {
             function F() {};
             F.prototype = old;
             return new F();
            }
        var newObj = object(oldObject);
    

12. List the values ​​of display and explain their function. The value of position, relative and absolute positioning origin?

  1.    block 象块类型元素一样显示。
  none 缺省值。向行内元素类型一样显示。
  inline-block 象行内元素一样显示,但其内容象块类型元素一样显示。
  list-item 象块类型元素一样显示,并添加样式列表标记。

  2. 
  *absolute 
        生成绝对定位的元素,相对于 static 定位以外的第一个父元素进行定位。 

  *fixed (老IE不支持)
        生成绝对定位的元素,相对于浏览器窗口进行定位。 

  *relative 
        生成相对定位的元素,相对于其正常位置进行定位。 

  * static  默认值。没有定位,元素出现在正常的流中
  *(忽略 top, bottom, left, right z-index 声明)。

  * inherit 规定从父元素继承 position 属性的值。

13. How does page refactoring work?

编写 CSS、让页面结构更合理化,提升用户体验,实现良好的页面效果和提升性能。

14. Semantic understanding?

html语义化就是让页面的内容结构化,便于对浏览器、搜索引擎解析;
在没有样式CCS情况下也以一种文档格式显示,并且是容易阅读的。
搜索引擎的爬虫依赖于标记来确定上下文和各个关键字的权重,利于 SEO。
使阅读源代码的人对网站更容易将网站分块,便于阅读维护理解。

15. Offline storage of HTML5?

localStorage    长期存储数据,浏览器关闭后数据不丢失;
sessionStorage  数据在浏览器关闭后自动删除。

16. Why initialize CSS styles.

  • Due to browser compatibility issues, different browsers have different default values ​​for some tags. If CSS is not initialized, there will often be differences in page display between browsers.

  • Of course, initializing the style will have a certain impact on SEO, but you can't have both, but try to initialize with the least impact.

*The easiest way to initialize is: * {padding: 0; margin: 0;} (not recommended)

    淘宝的样式初始化: 
    body, h1, h2, h3, h4, h5, h6, hr, p, blockquote, dl, dt, dd, ul, ol, li, pre, form, fieldset, legend, button, input, textarea, th, td { margin:0; padding:0; }
    body, button, input, select, textarea { font:12px/1.5tahoma, arial, \5b8b\4f53; }
    h1, h2, h3, h4, h5, h6{ font-size:100%; }
    address, cite, dfn, em, var { font-style:normal; }
    code, kbd, pre, samp { font-family:couriernew, courier, monospace; }
    small{ font-size:12px; }
    ul, ol { list-style:none; }
    a { text-decoration:none; }
    a:hover { text-decoration:underline; }
    sup { vertical-align:text-top; }
    sub{ vertical-align:text-bottom; }
    legend { color:#000; }
    fieldset, img { border:0; }
    button, input, select, textarea { font-size:100%; }
    table { border-collapse:collapse; border-spacing:0; } 

17.(写)描述一段语义的html代码吧。

    (HTML5中新增加的很多标签(如:<article>、<nav>、<header>和<footer>等)
     就是基于语义化设计原则)  

        < div id="header"> 
        < h1>标题< /h1> 
        < h2>专注Web前端技术< /h2> 
        < /div>
  • 语义 HTML 具有以下特性:

    文字包裹在元素中,用以反映内容。例如:
    段落包含在 <p> 元素中。
    顺序表包含在<ol>元素中。
    从其他来源引用的大型文字块包含在<blockquote>元素中。
    HTML 元素不能用作语义用途以外的其他目的。例如:
    <h1>包含标题,但并非用于放大文本。
    <blockquote>包含大段引述,但并非用于文本缩进。
    空白段落元素 ( <p></p> ) 并非用于跳行。
    文本并不直接包含任何样式信息。例如:
    不使用 <font> 或 <center> 等格式标记。
    类或 ID 中不引用颜色或位置。
    

18.absolute的containing block计算方式跟正常流有什么不同?

19.position跟display、margin collapse、overflow、float这些特性相互叠加后会怎么样?

20.对BFC规范的理解?(W3C CSS 2.1 规范中的一个概念,它决定了元素如何对其内容进行定位,以及与其他元素的关 系和相互作用。)

21.iframe有那些缺点?

    *iframe会阻塞主页面的Onload事件;

    *iframe和主页面共享连接池,而浏览器对相同域的连接有限制,所以会影响页面的并行加载。
    使用iframe之前需要考虑这两个缺点。如果需要使用iframe,最好是通过javascript
    动态给iframe添加src属性值,这样可以可以绕开以上两个问题。

22.css定义的权重

以下是权重的规则:标签的权重为1,class的权重为10,id的权重为100,以下例子是演示各种定义的权重值:

/*权重为1*/
div{
}
/*权重为10*/
.class1{
}
/*权重为100*/
#id1{
}
/*权重为100+1=101*/
#id1 div{
}
/*权重为10+1=11*/
.class1 div{
}
/*权重为10+10+1=21*/
.class1 .class2 div{
} 

如果权重相同,则最后定义的样式会起作用,但是应该避免这种情况出现

23.eval是做什么的?

它的功能是把对应的字符串解析成JS代码并运行;
避免使用eval,不安全,非常耗性能(2次,一次解析成js语句,一次执行)。

23.写一个通用的事件侦听器函数

`// event(事件)工具集,来源:https://github.com/markyun
markyun.Event = {
    // 页面加载完成后
    readyEvent : function(fn) {
        if (fn==null) {
            fn=document;
        }
        var oldonload = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = fn;
        } else {
            window.onload = function() {
                oldonload();
                fn();
            };
        }
    },
    // 视能力分别使用dom0||dom2||IE方式 来绑定事件
    // 参数: 操作的元素,事件名称 ,事件处理程序
    addEvent : function(element, type, handler) {
        if (element.addEventListener) {
            //事件类型、需要执行的函数、是否捕捉
            element.addEventListener(type, handler, false);
        } else if (element.attachEvent) {
            element.attachEvent('on' + type, function() {
                handler.call(element);
            });
        } else {
            element['on' + type] = handler;
        }
    },
    // 移除事件
    removeEvent : function(element, type, handler) {
        if (element.removeEnentListener) {
            element.removeEnentListener(type, handler, false);
        } else if (element.datachEvent) {
            element.detachEvent('on' + type, handler);
        } else {
            element['on' + type] = null;
        }
    }, 
    // 阻止事件 (主要是事件冒泡,因为IE不支持事件捕获)
    stopPropagation : function(ev) {
        if (ev.stopPropagation) {
            ev.stopPropagation();
        } else {
            ev.cancelBubble = true;
        }
    },
    // 取消事件的默认行为
    preventDefault : function(event) {
        if (event.preventDefault) {
            event.preventDefault();
        } else {
            event.returnValue = false;
        }
    },
    // 获取事件目标
    getTarget : function(event) {
        return event.target || event.srcElement;
    },
    // 获取event对象的引用,取到事件的所有信息,确保随时能使用event;
    getEvent : function(e) {
        var ev = e || window.event;
        if (!ev) {
            var c = this.getEvent.caller;
            while (c) {
                ev = c.arguments[0];
                if (ev && Event == ev.constructor) {
                    break;
                }
                c = c.caller;
            }
        }
        return ev;
    }
}; 

24.99%的网站都需要被重构是那本书上写的?

* 网站重构:应用web标准进行设计(第2版)

25.什么叫优雅降级和渐进增强?

优雅降级:Web站点在所有新式浏览器中都能正常工作,如果用户使用的是老式浏览器,则代码会检查以确认它们是否能正常工作。由于IE独特的盒模型布局问题,针对不同版本的IE的hack实践过优雅降级了,为那些无法支持功能的浏览器增加候选方案,使之在旧式浏览器上以某种形式降级体验却不至于完全失效.

渐进增强:从被所有浏览器支持的基本功能开始,逐步地添加那些只有新式浏览器才支持的功能,向页面增加无害于基础浏览器的额外样式和功能的。当浏览器支持时,它们会自动地呈现出来并发挥作用。

26.Node.js的适用场景

高并发、聊天、实时消息推送

27.WEB应用从服务器主动推送Data到客户端有那些方式?

    html5 websoket
    WebSocket通过Flash
    XHR长时间连接
    XHR Multipart Streaming
    不可见的Iframe
    <script>标签的长时间连接(可跨域)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324886436&siteId=291194637