banner-image

4.6 Created by potrace 1.15, written by Peter Selinger 2001-2017

5.0 Created by potrace 1.15, written by Peter Selinger 2001-2017

4.6 Created by potrace 1.15, written by Peter Selinger 2001-2017

CSS Interview Questions CSS FAQ


Hi, Welcome to Monopoly IT Solutions, our Interview Questions / FAQs can be very helpful for interview preparation in several ways:

  • Understanding the way how Questions are asked by interviewer
  • Practicing Answers, find our appropriate ways of answeringand excel the interview
  • Gaining Insight into the industry standard
  • Reducing Anxiety of Interview
  • Self analysis of Key Skills

Following are the conceptual theory questions

  • Cascading Style Sheets (CSS) is a stylesheet language used to describe the presentation of a document written in HTML or XML.There are three ways of inserting a style sheet:
    • External CSS
    • Internal CSS
    • Inline CSS

  • The CSS box model is a fundamental concept in web development that defines how HTML elements are displayed on a page. It's a box that surrounds every HTML element and consists of four components: content, padding, border, and margin.
    • Content box: The area where the text and images appear
    • Padding box: A transparent space around the content
    • Border box: A border that surrounds the padding and content
    • Margin box: A transparent space around the border, separating it from other elements

  • In CSS, classes and IDs are both used to target elements for styling. The main difference between them is that a class can be applied to multiple elements, while an ID is unique to a single element.
  • Example:

  • CSS3 or Cascading Style Sheets Level 3 is an improved and refined Versions of CSS with certain advanced features like media queries, transitions, 3D transformations, shadows, gradients, border images, and many more to make your website visually more appealing. CSS3 helps create more complex designs that help define the appearance of web pages. CSS3 is supported by almost all modern web browsers like google chrome, firefox, safari, Opera, etc.

  • In CSS, both display:none and visibility:hidden can hide elements on a screen, but they cause the element to behave differently:
    • Display:none - Removes the element from the document and turns off its layout, so it's not rendered. For example, you can use display:none to hide a sidebar, popup, or todo list item.
    • Visibility:hidden - Hides the element but keeps its original position and size, and it still takes up space in the layout. For example, you can use visibility:hidden to display an animation while hiding or showing an element.

  • Inline-block elements combine characteristics of both block and inline elements. They do not start on a new line like block elements, but they allow other elements to sit beside them on the same line, similar to inline elements.

  • To change an Inline-level Element into a Block-level Element, you can use the display property in CSS. The display property allows you to specify the type of box used for an HTML elements layout. Here's how you can make an inline-level element into a block-level element:
    • Using display: block;
    • Using display: inline-block;

  • The position property specifies the type of positioning method used for an element (static, relative, absolute, fixed, or sticky).

  • Display properties can help create flexible and responsive designs. For example, the display: contents property makes an element's children appear as if they were direct children of its parent, which can be useful when using CSS grid or similar layout techniques. The display: flex value sets an element as a flex container, which is another way to build dynamic and responsive elements.

  • The !important rule in CSS is used to add more importance to a property/value than normal. In fact, if you use the !important rule, it will override ALL previous styling rules for that specific property on that element!

  • CSS stands for Cascading Style Sheets. It is used for describing the presentation of a document written in HTML or XML, including aspects like layout, colors, fonts, etc.

  • There are three main ways to apply CSS:
    • Inline CSS (using the style attribute directly on HTML elements)
    • Internal CSS (using style tags within the head section of an HTML document)
    • External CSS (linking to an external CSS file using the < link> tag)

  • Specificity determines which CSS rule is applied by the browser when multiple conflicting rules target the same element. It is calculated based on the type of selector used (e.g., element selectors, class selectors, ID selectors) and the number of these selectors in a rule.

  • A pseudo-class in CSS is used to define a special state of an element. For example, :hover is a pseudo-class that applies when an element is being hovered over by the mouse pointer.

  • The float property is used for positioning and formatting content, allowing an element to be pushed to the left or right and to have content flow around it.

  • You can create a responsive website by using techniques like media queries (@media rule), flexible grid layouts (e.g., using flexbox or CSS Grid), and fluid images (using max-width: 100%;).

  • The main advantages of CSS are given below:
    • Separation of content from presentation - CSS provides a way to present the same content in multiple presentation formats in mobile or desktop or laptop.
    • Easy to maintain - CSS, built effectively can be used to change the look and feel complete by making small changes. To make a global change, simply change the style, and all elements in all the web pages will be updated automatically.
    • Bandwidth - Used effectively, the style sheets will be stored in the browser cache and they can be used on multiple pages, without having to download again.

  • Disadvantages of CSS are given below:
    • Browser Compatibility: Some style selectors are supported and some are not. We have to determine which style is supported or not using the @support selector.
    • Cross Browser issue: Some selectors behave differently in a different browser.
    • There is no parent selector: Currently, Using CSS, you can’t select a parent tag

  • CSS3 is the latest version of CSS.

  • RGBA contains A (Alpha) which specifies the transparency of elements. The value of alpha lies between 0.0 to 1.0 where 0.0. represents fully transparent and 1.0 represents not transparent.

  • HSL: HSL stands for Hue, Saturation, and Lightness respectively. This format uses the cylindrical coordinate system.
    • Hue: Hue is the degree of the color wheel. Its value lies between 0 to 360 where 0 represents red, 120 represents green and 240 represents a blue color.
    • Saturation: It takes a percentage value, where 100% represents completely saturated, while 0% represents completely unsaturated (gray).
    • Lightness: It takes a percentage value, where 100% represents white, while 0% represents black.

    • CSS border properties allow us to set the style, color, and width of the border.
    • CSS outline property allows us to draw a line around the element, outside the border.

  • The ruleset is used for the identification of selectors, which can be attached with other selectors. The two parts of a ruleset are:
    • Declaration block: contains one or more semicolon-separated declarations
    • Sector: indicates the HTML element needed to be styled

  • There are three ways of integrating CSS into HTML: using style tags in the head section, using inline-styling, writing CSS in a separate file, and linking into the HTML page by the link tag.

  • Identification of selectors that can be linked to other selectors is done by the ruleset.

  • There is no case sensitivity in CSS, although font families and URLs have case sensitivity.

  • /* and */ can be used to add comments in CSS.

  • An attribute selector is a set of values, elements, and their parts.

  • Property is a style that helps in influencing the CSS language. They contain corresponding properties or values within them. Eg. Font, which has different styles like italic, bold, etc.

  • CSS frameworks are libraries to create webpage styling much easier. Some of them are Foundation, Gumby, Ukit, Bootstrap, Semantic UI, etc.

  • Float is a CSS property written in a CSS file or directly in the style of an element. The float property defines the flow of content. Below are the types of floating properties:
    Float typeUsage
    float: leftElement floats on the left side of the container
    float: rightElement floats on the right side of the container
    float: inheritThe element inherits the floating property of its parent (div, table, etc…)
    float: noneElement is displayed as it is (Default).

  • The position property in CSS tells about the method of positioning for an element or an HTML entity. There are five different types of position properties available in CSS:
    • Fixed
    • Static
    • Relative
    • Absolute
    • Sticky

  • The CSS overflow controls the big content. It tells whether to clip content or to add scroll bars. The overflow contains the following property:
    • visible
    • hidden
    • scroll
    • auto

  • The style display property is used to hide and show the content of HTML DOM by accessing the DOM element using JavaScript/jQuery.
    • To hide an element, set the style display property to “none”. display: "none";
    • To show an element, set the style display property to “block”. display:"block";

  • CSS text formatting properties are used to format text and style text. CSS text formatting includes the following properties:
    • Text-colot
    • Text-alignment
    • Text-decoration
    • Text-transformation
    • Text-indentation
    • Letter spacing
    • Line height
    • Text-direction
    • Text-shadow
    • Word spacing

    • Margin is used to create space around elements and padding is used to create space around elements inside the border.
    • We can set the margin property to auto but we cannot set the padding property to auto.
    • In Margin property we can allow negative or float number but in padding we cannot allow negative values.
    • Margin and padding target all the 4 sides of the element. Margin and padding will work without the border property also.

  • CSS border properties allow us to set the style, color, and width of the border.
    • Border Style: The border-style property specifies the type of border. None of the other border properties will work without setting the border style.
    • Border Width: Border width sets the width of the border. The width of the border can be in px, pt, cm or thin, medium and thick.
    • Border Color: This property is used to set the color of the border. Color can be set using the color name, hex value, or RGB value. If the color is not specified border inherits the color of the element itself.

  • Inline-block: This feature uses both properties: block and inline. So, this property aligns the div inline but the difference is it can edit the height and the width of the block. Basically, this will align the div both in the block and inline fashion.

  • Given an image and the task is to set the image to align to centre (vertically and horizontally) inside a bigger div. It can be done by using the position property of the element.
  • Example: This example uses the position property to make the image align to the centre

  • Creating an overlay effect simply means putting two div together at the same place but both the div appear when needed i.e while hovering or while clicking on one of the div to make the second one appear. Overlays are very clean and give the webpage a tidy look. It looks sophisticated and is simple to design. Overlays can create using two simple CSS properties:
    • The z-index property is used to displace elements on the z-axis i.e in or out of the screen. It is used to define the order of elements if they overlap with each other.
    • Syntax: z-index: auto|number|initial|inherit;

Following are the coding based questions

getintouch

Book for Live Demo!