Exam NameCSS Interview QUESTIONS
DescriptionCSS Interview QUESTIONS contains the questions from various interview of IT industry.These questions are helpful to crack the IT interview.

Back to Parent Category
Create QuestionPDF  
Question: What is CSS?

Answer:CSS is a standard for applying style to HTML elements. This styling includes margins, positioning, fonts, colors, and so forth. The styling can apply to the complete document or be granular and apply to a specific element. Theoretically, the use of CSS promotes the separation of content and design, allowing the designer to focus on how a Web application will look while the developer(s) concentrate on the structure and functionality.

The main part of CSS is a rule. A rule consists of a selector (i.e., what will be styled) followed by a declaration (i.e., the style to be applied) that is broken into one or more properties and associated styles. In the following example, h1 is the selector, followed by the color property and the style of blue.

Question: What does the cascading portion of CSS mean?

Answer:Cascading refers to cascading order. It is a system of sorting the various CSS declarations to avoid conflicts. The process begins with a search for all declarations that apply to specific elements; it ends if no match is found. Cascading occurs if multiple styles are defined for an element. In general, values will be applied from the more specific style sheet.

Question: Is CSS case-sensitive?

Answer:The CSS standard is not case-sensitive, but if an XHTML doctype is used, then CSS class names will be case-sensitive in some browsers. In addition, items like font families, image URLs, and other direct references with the style sheet can be case-sensitive. To be safe, you should stick with lower-case to avoid confusion or unexpected problems.

Question: What are different ways to apply styles to a Web page?

Answer:There are four ways to integrate CSS into a Web page (some consider items three and four the same):

  • Inline: HTML elements may have CSS applied to them via the STYLE attribute.

  • Embedded: CSS may be embedded in a Web page by placing the code in a STYLE element within the HEAD element.

  • Linked: CSS may be placed in an external file (a simple text file containing CSS) and linked via the link element.

  • Imported: Another way to utilize external CSS files via @import.

Question: What is an ID selector?

Answer:An ID selector is a name assigned to a specific style. In turn, it can be associated with one HTML element with the assigned ID. Within CSS, ID selectors are defined with the # character followed by the selector name. The name can contain characters a-z, A-Z, digits 0-9, period, hyphen, escaped characters, and so forth.

The following snippet shows the CSS example1 defined followed by the use of an HTML element's ID attribute, which pairs it with the CSS selector.

Question: What is a class?

Answer:A class is a style (i.e., a group of CSS attributes) that can be applied to one or more HTML elements. This means it can apply to instances of the same element or instances of different elements to which the same style can be attached. Classes are defined in CSS using a period followed by the class name. It is applied to an HTML element via the class attribute and the class name.

Question: What is the difference between an ID selector and CLASS?

Answer:An ID selector identifies and sets style to only one occurrence of an element, while CLASS can be attached to any number of elements.

Question: What is contextual selector?

Answer:Contextual selector addresses specific occurrence of an element. It is a string of individual selectors separated by white space (search pattern), where only the last element in the pattern is addressed providing it matches the specified context.

Question: What is grouping?

Answer:When more than one selector shares the same declaration, they may be grouped together via a comma-separated list; this allows you to reduce the size of the CSS (every bit and byte is important) and makes it more readable. The following snippet applies the same background to the first three heading elements.

h1, h2, h3 {background: red;}

Question: What are child selectors?

Answer:A child selector is used when you want to match an element that is the child of another specific element. The parent and child selectors are separated by spaces. The following selector locates an unordered list element within a paragraph element and makes a text within that element bold.

p > ul {font-weight: bold;}

Question: What are pseudo classes?

Answer:Pseudo classes allow you to identify HTML elements on characteristics (as opposed to their name or attributes). The classes are specified using a colon to separate the element name and pseudo class. A good example is the :link and :visited pseudo classes for the HTML A element. Another good example is first-child, which finds an element's first child element.

The following CSS makes all visited links red and green, the actual link text becomes yellow when the mouse pointer is positioned over it, and the text of the first element of a paragraph is bold.

a:link {font-color: red;}
a:visited {font-color: green;}

a:hover {font-color: yellow;}
p.first-child {font-weight: bold;}

Question: How do you include comments in CSS?

Answer:Anything placed between /* and */ in CSS is considered a comment. Comments are ignored by the browser.