Recruiters

CSS Interview Questions and Answers

css interview questions and answers


CSS Interview Questions and Answers

What CSS properties can change dimensions, describe them.

    • height: Sets a specific height
      • auto
      • length
      • %
      • inherit
    • width: Sets a specific width
      • auto
      • length
      • %
      • inherit
    • max-height: Sets a maximum height
      • auto
      • length
      • %
      • inherit
    • max-width: Sets a maximum width
      • auto
      • length
      • %
      • inherit
    • min-height: Sets a minimum height
      • auto
      • length
      • %
      • inherit
    • min-width: Sets a minimum width
      • auto
      • length
      • %
      • inherit

How do you use a pseudo class?

    • Pseudo classes are similar to classes, but are not explicitly defined in the markup, and are used to add additional effects to selected HTML elements such as link colors, hover actions, etc.
    • Pseudo classes are defined by first listing the selector, followed by a colon and then pseudo-class element. E.g.,  a:link{ color: blue }, or a:visited { color: red }
      • Pseudo-class syntax:

selector:pseudo-class {
property:value;}

      • Syntax for using a pseudo class within a CSS class:

selector.class:pseudo-class {
property:value;}

How do you use grouping?

e.g.)  h1, h2  { font-family: Helvetica; font-size: 20; }

How do you use shorthand properties ?.

e.g.) Code snippet ‘a’ gets shorthanded into code snippet ‘b’ by condensing the property values (in order) onto a single line:

a)

HTML Css Coding

b)

HTML Css Coding

Indicate how to attach style sheets to a web page:

html-css-coding-screenshot

css coding, web page styles

    • :link, :visited, :hover, :active, :first_line are all examples of pseudo classes, used to call a specific action on an element, such as the changing of a link color after it has been visited.
      • Grouping allows you to apply the same style to multiple elements with a single declaration. This is done by grouping the selectors into a list, separated by commas.

    How is a class selector used?

    Within an HTML doc:

    Class Selector

    Within a CSS doc:

    Class Selector

      • Grouping helps memory usage and enhances readability.
        • A class can be thought of as a grouped collection of CSS attributes applied to HTML elements. This allows you to apply the same styling to multiple HTML elements by placing them in the same CSS class.
        • Class methods can be called by inserting a ‘class’ property and name within an HTML element, then calling the class name with a ‘.’  in the CSS doc.
        • Class syntax:
        • The code listed here identifies the class ‘intro’ in the HTML doc, then applies the same background-color styling to all paragraphs within that class.
      • Using shorthand properties can improve page load times and reduce file size.
      • Can be done with background, font, border, padding, outline, and list-style properties.
      • Shorthanding is accomplished by listing the property values on a single line, in a specific order.
      • Inline: Though this method often goes against best practices, it’s easily done by inserting a ‘style’ attribute inside an HTML element:
        • e.g.) <p style=”color:blue”>Lorem Ipsum</p>
      • Embedded/Internal: Done by defining the head of an HTML document by wrapping characteristics in a <style> tag.
      • Linked/External: CSS is placed in an external .css file, and linked to the HTML document with a <link> tag. This can also be accomplished using the ‘@import’, however, this can slow page load time and is generally not advised.

How do you use a ID selector?

    • IDs are used to identify and apply styling to a single specific HTML element. IDs are defined within the HTML page by inserting an ID selector in the HTML element:
      • eg)

HTML CSS Coding

    • ID selectors are defined within the CSS page by calling a ‘#’ followed by the name of the ID:
      • eg)

HTML CSS Coding

    • ID selectors are unique and can only be applied to a single element.

What is the difference between a Class selector and a ID selector?

    • Class selectors are used to apply style to multiple HTML identified with the same class.
      • Within the HTML doc:
        • e.g.)

HTML Css Coding

    • Class selectors are called within the CSS document by a ‘.’, followed by the class name:
      • Within the CSS doc:
        • e.g.)

HTML Css Coding

    • The main difference is that the same class selector can be applied to multiple HTML elements, whereas ID selectors are unique..

Explain child selectors?

    • Child selectors are another way to group and style a set of elements that descend from a parent element.
    • A child selector is matched by calling two or more elements, separated by a ‘>’ sign to indicate inheritance.

e.g.)

html-css-coding-9-620x115

    • In this example, the same styling would be applied to all paragraphs within the body.

How do you use the float property in CSS?

    • Floats allow an element to be positioned horizontally, allowing elements below the floated element to flow around it. Several floating elements can be placed together to make a gallery type layout.
    • Floats can only accept a left or right value.
      • e.g.)

img {
float: right;
width: 50px;
margin: 5px;
}

    • To prevent subsequent elements from flowing around the floated element, pass in the clear property, followed by the side you wish to disable (i.e., ‘left’, ‘right’, ‘both’).

How do you use the CSS box model? What elements does it include?

    • CSS box model is made up of margins, borders, padding, and content.
    • Box model provides a structured way to space elements in relationship to each other.

W3 Schools

How to restore the default property value using CSS?

    • In short, there’s no easy way to restore to default values to whatever a browser uses . The closest option is to use the ‘initial’ property value, which will restore it to the default CSS values, rather than the browser’s default styles.

How do you use pseudo-elements?

    • Pseudo elements are made using a double colon (::) followed by the name of the pseudo element.
    • Pseudo-elements are used to add special effects to some selectors, and can only be applied to block-level elements.
    • Most commonly used pseudo-elements are ::first_line, ::first_letter, ::before, ::after

How are inline and block elements different from each other?

    • A block element is an element that takes up the full width available, and has a line break before and after it. <h1>, <p>, <li>, and <div> are all examples of block elements.
    • An inline element only takes up as much width as necessary, cannot accept width and height values, and does not force line breaks. <a> and <span> are examples of inline elements.

How do you use the z-index property?

    • The z-index helps specify the stack order of positioned elements that may overlap one another. The z-index default value is zero, and can take on either a positive or negative number.
    • An element with a higher z-index is always stacked above one with a lower index.
    • Z-Index can take the following values:

Auto: Sets the stack order equal to its parents.

Number: Orders the stack order.

Initial: Sets this property to its default value (0).

Inherit: Inherits this property from its parent element.

What are the advantages and disadvantages of External Style Sheets?

    • The biggest advantages of external style sheets are that they can be applied to multiple documents while being managed from a single style sheet. This keeps code DRY and improves efficiency and convenience.
    • The disadvantages are that it may decrease loading time in some situations. It may also not be practical if there are not enough styling conditions to justify an external sheet.

List the main CSS style sheet properties:

    • Background
    • Text
    • Font
    • Border
    • Outline
    • Margin
    • Padding
    • List
    • Table

Which online resources do you refer to when having issues with CSS?

    • No real correct answer here, save for being able to discuss  your favorite online CSS community forums and resources. e.g. Mozilla Developer Network, StackOverflow, etc.
    • This is just your opportunity to discuss larger CSS issues and show how plugged-in you are to the community.

What are the various techniques for clearing floats?

    • At some point or another, you will likely experience a collapsed float, which you will need to address.
    • This can be accomplished several ways, including using a clearfix2 by floating the parent element of the collapsed element, or by using an overflow property3.

 Explain the difference between visibility:hidden and display:none

    • visibility:hidden simply hides the element, while it will still take up space and affect the layout of the document.
    • display:none also hides the element, but will not take up space and the page will appear as if the element is not present.

What are some of the new features and properties in CSS3?

    • Box model
    • New Web fonts
    • Rounded corners
    • Border Images
    • Box Shadows, Text Shadows
    • New Color schemes (RGBA)
    • Transform property
    • New Pseudo-classes
    • Multi-column layout
    • New Gradients

Why shouldn’t I use fixed sized fonts ?

    • Often times, fixed font sizes will show up incorrectly on the user end and will prohibit responsiveness. Using relative sizing will keep fonts proportionate in their relationships to each other and will allow for greater end user flexibility.

Which font names are available on all platforms ?

    • Only five basic font families( serif, sans-serif, cursive, fantasy, and monsospace) are recognized across platforms, rather than specific fonts.
    • Specific font name recognitions will vary by browser.

Do you use grid systems, and if so, what do you prefer?

    • Again, no correct answer here. Just be able to discuss the pros and cons of different grid systems, mobile-first, fluid and responsive web design issues.

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

    • Here is another opportunity to discuss your personal preferences on use of CSS preprocessors and why.
    • While there’s no right or wrong answer here, below are some commonly cited pros and cons of using preprocessors:

Benefits: Ability to use nested sytax, define variables and mixins, use of mathematical and operational functions, and the ability to join multiple files into a single one.

Disadvantages: Difficulties tracking file size, maintenance and updating issues, difficulties debugging.

Published: 1st June 2016 by

Adverts