mzhong

matthew.zhong's site

  • Home
  • Contact
  • Archives
  • Categories
  • Tag
  • RSS

    CSS Questions:Front-end Developer Interview Questions

    19 Nov 2013

    Describe what a "reset" CSS file does and how it's useful.

    • What Is A CSS Reset?
      A CSS Reset (or “Reset CSS”) is a short, often compressed (minified) set of CSS rules that resets the styling of all HTML elements to a consistent baseline. In a word,reset.css is used to normalize browser's default styles.
    • Why USE A CSS Reset?
      Browser have different "built-in" styles which they apply to different html-elements. These styledefinitions may vary accross different browsers.
    • Which CSS Reset Should I Use?

      • Normalize.css is a customisable CSS file that makes browsers render all elements more consistently and in line with modern standards.
      • If you’re working with HTML5, use the HTML5 Doctor Reset CSS
      • If you’re doing some quick prototyping and testing, or building a non-HTML5 page, use Eric Meyer’s Reset CSS.
      • If you want a CSS Reset that acts more as a framework, un-resetting styles after the CSS Reset, use the Tripoli CSS Reset or the Vanilla CSS Un-Reset
      • If you want a full-featured CSS Framework, try using and abusing all the modules of the YUI 3 CSS Library
      • Generally speaking, don’t use the Universal Selector ‘*’ CSS Reset

    Describe Floats and how they work.

    A float element in page like a boat in water.

    What are the various clearing techniques and which is appropriate for what context?

    • The Empty Div Method is, quite literally, an empty div. <div style="clear: both;"></div>. Sometimes you'll see a <br /> element or some other random element used, but div is the most common because it has no brower default styling, doesn't have any special function, and is unlikely to be generically styled with CSS. This method is scorned by semantic purists since its presence has no contexual meaning at all to the page and is there purely for presentation. Of course in the strictest sense they are right, but it gets the job done right and doesn't hurt anybody.
    • The Overflow Method relies on setting the overflow CSS property on a parent element. If this property is set to auto or hidden on the parent element, the parent will expand to contain the floats, effectively clearing it for succeeding elements. This method can be beautifully semantic as it may not require an additional elements. However if you find yourself adding a new div just to apply this, it is equally as unsemantic as the empty div method and less adaptable. Also bear in mind that the overflow property isn't specifically for clearing floats. Be careful not to hide content or trigger unwanted scrollbars.
    • The Easy Clearing Method uses a clever CSS pseudo selector (:after) to clear floats. Rather than setting the overflow on the parent, you apply an additional class like "clearfix" to it. Then apply this CSS:
        .clearfix:after {       
            content: ".";       
            visibility: hidden;       
            display: block;       
            height: 0;       
            clear: both;
        }
        
    
    This will apply a small bit of content, hidden from view, after the parent element which clears the float. This isn't quite the [whole story](http://www.positioniseverything.net/easyclearing.html), as additional code needs to be used to accomodate for older browsers.
    

    Explain CSS sprites, and how you would implement them on a page or site.

    CSS sprites are a way to reduce the number of HTTP requests made for image resources referenced by your site. Images are combined into one larger image at defined X and Y coorindates. Having assigned this generated image to relevant page elements the background-position CSS property can then be used to shift the visible area to the required component image.(Css sprites is a technology to combin many image into one, and use css background-position to find which part you want)

    CSS Sprites are the preferred method for reducing the number of image requests. Combine your background images into a single image and use the CSS background-image and background-position properties to display the desired image segment.

    What are your favourite image replacement techniques and which do you use when?

    CSS image replacement is a technique of replacing a text element (usually a header tag) with an image.
    css-image-replacement

    CSS property hacks, conditionally included .css files, or... something else?

    How do you serve your pages for feature-constrained browsers?

    What techniques/processes do you use?

    • Progressive Enhancement
    • Graceful Degradation

    What are the different ways to visually hide content (and make it available only for screen readers)?

    css media types

    Have you ever used a grid system, and if so, what do you prefer?

    Of course yes.

    • gridpak. A simple grid system.
    • Bootstrap Grid System
    • Grid960
    • YUI CSS Grid

    I prefer Bootstrap grid.

    Have you used or implemented media queries or mobile specific layouts/CSS?

    Of course yes.
    I implemented media queries on my gitbub pages.the site works fine on all media included handle devices.

    Any familiarity with styling SVG?

    SVG styling

    How do you optimize your webpages for print?

    • Create A Stylesheet For Print
    • Avoid Unnecessary HTML Tables
    • Hiding Needless Element For Print
    • Size Page For Print
    • Use Page Break

    What are some of the "gotchas" for writing efficient CSS?

    • Use efficient CSS selectors
      • Avoid a universal key selector.
        Allow elements to inherit from ancestors, or use a class to apply a style to multiple elements.
      • Make your rules as specific as possible.
        Prefer class and ID selectors over tag selectors.
      • Remove redundant qualifiers.
        These qualifiers are redundant:
        • ID selectors qualified by class and/or tag selectors
        • Class selectors qualified by tag selectors (when a class is only used for one tag, which is a good design practice anyway).
      • Avoid using descendant selectors, especially those that specify redundant ancestors.
        For example, the rule body ul li a {...} specifies a redundant body selector, since all elements are descendants of the body tag.
      • Use class selectors instead of descendant selectors.
    • Avoid CSS expressions
    • Put CSS in the document head

    What are the advantages/disadvantages of using CSS preprocessors? (SASS, Compass, Stylus, LESS)

    If so, describe what you like and dislike about the CSS preprocessors you have used.

    How would you implement a web design comp that uses non-standard fonts?

    Webfonts (font services like: Google Webfonts, Typekit etc.)  
    

    Explain how a browser determines what elements match a CSS selector?

    As the browser parses HTML, it constructs an internal document tree representing all the elements to be displayed. It then matches elements to styles specified in various stylesheets, according to the standard CSS cascade, inheritance, and ordering rules. In Mozilla's implementation (and probably others as well), for each element, the CSS engine searches through style rules to find a match. The engine evaluates each rule from right to left, starting from the rightmost selector (called the "key") and moving through each selector until it finds a match or discards the rule. (The "selector" is the document element to which the rule should apply.)

    Explain your understanding of the box model and how you would tell the browser in CSS to render your layout in different box models.

    All HTML elements can be considered as boxes. In CSS, the term "box model" is used when talking about design and layout.

    The CSS box model is essentially a box that wraps around HTML elements, and it consists of: margins, borders, padding, and the actual content.

    Important: When you set the width and height properties of an element with CSS, you just set the width and height of the content area. To calculate the full size of an element, you must also add the padding, borders and margins.

    IE8 and earlier versions of IE, included padding and border in the width property.
    To fix this problem, add a <!DOCTYPE html> to the HTML page.

    The box-sizing CSS property is used to alter the default CSS box model used to calculate widths and heights of elements. It is possible to use this property to emulate the behavior of browsers that do not correctly support the CSS box model specification.

    MZhong's Cover Letter

    18 Nov 2013

    Application for front-end developer position in Chicago Office

    Dear HR,

    I am writing to apply for the Front End Web Developer position posted on our company website.

    I have a master's degree in computer educational technology and focused on web front-end development for seven years.I joined Morningstar in 2011 and joined Mercury Manager Research in 2012.

    I am proficient using Semantic HTML, CSS3, Javascript, jQuery, Backbone and Angular.I have many experiences for building SPA(Single Page Application). I implemented some modules with TDD and set up the front-end unit test environment with karma and jasmine for Mercury Manager Research.My previous experience also includes building landing pages, performing split tests, tracking and analyzing websites to look for ways to make improvements.

    I enjoy working in a team.I am also productive and focused working independently.I am confident that I am the best applicant for this job.I look forward to getting the chance.

    Thank you very kindly for your consideration.

    Sincerely,
    Mathew Zhong

    6 Floor, Tower A, Donghai International Center, 7888 Shennan Road, Futian District, Shenzhen, Guangdong, China, 518040

    Tele: 8675533110204

    Phone: 8618676730824

    Email: matthew.zhong@morningstar.com

    MZhong's Resume

    15 Nov 2013

    MATTHEW.ZHONG

    Male,27 Age
    Front-End Developer
    matthew.zhong@morningstar.com

    OBJECTIVE

    My objective is to build SaaS App(also Single Page App) by using advanced technologies like HTML5/CSS3/NODE/MVVM.etc

    SKILL

    • Semantic HTML/XML/Emmet(zen-coding)/Markdown
    • CSS3/LESS/SASS/Grid/Responsive
    • Javascript/jQuery/Nodejs/CoffeeScript
    • Requirejs
    • Angularjs/Knockoutjs/Backbonejs
    • Gruntjs/karma/Jasmine/QUnit
    • SVG/Canvas/D3js
    • Python/PHP
    • Sublime Text/Visual Studio/Browsers DEVTools

    WORK EXPERIENCE

    • 2011 - Present
      Morningstar Shenzhen

      • 2011 - 2012 Asset Allocation
      • 2012 - Present Mercury/Manager Research
        • Translate wireframes, visual design specs
        • Build common ui components
        • JavaScript unit testing with Jasmine
    • 2010 - 2011
      Shenzhen 8aza
      www.hirede.com

    EDUCATION

    • Educational Technology Master Degree
      Sun Yat Sen University
      Graduated 2010

    • Educational Technology Bachelor Degree
      Harbin Normal University
      Graduated 2008

    CONTACT ME

    • GitHub
    • Twitter

    1st-code-review summary

    13 Nov 2013

    每次做code review,先贤谆谆教诲便在耳畔响起:

    “There are only two hard problems in Computer Science: cache invalidation and naming things.” —Phil Karlton

    将发现的问题整理如下:

    Hard Code

    这个永远是容易发现,也是最容易出现的问题,主要集中在 :

    • 配置项
         
            this.investmentList = [{
                id: "ALL",
                name: "All Investments"
            }, {
                id: "FE",
                name: "ETF"
            }, {
                id: "FV",
                name: "Insurance Product Fund"
            }, {
                id: "FO",
                name: "Open-End Fund"
            }, {
                id: "SA",
                name: "Separate Account"
            }];   
        
    
    • Labels
     
            if (data.length == 0) {
                //message hard code
                this.showMsgBox("No valid manager data available for the strategy.", true);
                this.hideBodyEl();
            }     
        
    
    • 逻辑标识
          
            if (dataType == 1) { // dataType == what 
                //compare the number type
            }
        
    

    单var模式与多var模式

    单var模式

    在函数的顶部使用唯一一个var语句是非常推荐的一种模式,它有如下一些好处:

    • 可以在同一个位置找到函数所需的所有变量
    • 避免在变量声明之前使用这个变量时产生的逻辑错误(参考下一小节“声明提前:分散的var带来的问题”)
    • 提醒你不要忘记声明变量,顺便减少潜在的全局变量
    • 代码量更少(输入代码更少且更易做代码优化)

    单var模式看起来像这样:

          
    function func() {
        var a = 1,
            b = 2,
            sum = a + b,
            myobject = {},
            i,
            j;
        // 函数体…
    }  
    

    对于单 var 模式和多 var 模式,建议不做强行约定,但同一个文件里,风格必须一致。

    命名规范

    • 引入外部资源
      • 应对引入的资源分组并以空行隔开,如mercury资源与mr资源,chartComponent资源与Grid资源,类与object...
      • 类名大驼峰,变量小驼峰,常量全大写
      • 不用给一些常用工具类起不同于exports的别名,如系统中是这样配置jquery,underscorejs
     
        'jquery': {
          deps: [],
          exports: '$',
          init: function() {
            return this.$.noConflict();
          }
        },  
        'underscore': {
          deps: [],
          exports: '_',
          init: function () {
            return this._.noConflict();
          }
        }
        
    
    • 方法名
      • 方法名拼写错误,如restFilterOption..
      • 太多的方法名以draw,load开头,有些名字不是很顾名思义

    方法参数不需要带下划线

    这一点我还没查到具体文档,待讨论

          
     renderUI: function(_el) { //_el => el
        _el.append(HTML);
        this.initParam();
        this._loadRequestParam();
        this.drawHeader();
        this._tableTemplate = null;
        this._tableData = null;
    }
    

    多用$el.empty().append(value),少用$el.html(value)

    $().html(value) vs $().empty().append(value)比较

    refs :

    single-var-mode
    html-vs-empty-append
    requireJs-config
    Airbnb JavaScript Style Guide

    Smart Tip

    12 Nov 2013

    构建了一个smar-tip的tooltip组件

    主要特性

    • 自动定位与边界查找
    • 支持8个方向与圆角
    • 自定义皮肤

    调用(Usage)

         
    var $container = $("#container"),
        $btn = $("#btn"),
        content = "苍井优的出道要追溯到公演于1999年的音乐剧《安妮》, " +
            "万人候选,她脱颖而出,被选中出演波丽一角。" +
            "后来她又被选为三井不动产的少女代言人," +
            "其清丽的形象一时间变得家喻户晓。";
    var smartTipInstance = new SmartTip({
        container: $container,
        trigger: $btn,
        content: content,
    
        borderColor: "#adadad",
        borderWidth: 1,
        borderRadius: 5,
        bgColor: "white",
        width: 160,
        height: 200,
        arrowSize: 10
    });
    
    smartTipInstance.show();
    

    demo

    demo

  • 1
  • 2
  • 3

Copyright © 2011-2013 Mzhong All rights reserved.