InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
Explain the rule set in CSS? |
|
Answer» CSS3 is the latest evolution extending CSS2. It has a lot of new features like selectors, rounded corners, border-image, text-shadow, BOX-shadow, transitions, animations, GRADIENTS, and grid LAYOUTS. Let us discuss each of them below.
|
|
| 2. |
What is specificity? |
|
Answer» PSEUDOCLASS :first-letter can refer to the first letter of the ELEMENT, paragraph as below. It is clean approach WITHOUT enclosing the first letter in span tag and applying the required RULE based on the representation. HTML <p>Booker T</p>CSS html { font-size: 3rem; } p::first-letter { border: 1px solid; font-weight: BOLD; color: red; } |
|
| 4. |
Mention types of selectors? |
|
Answer» Colors in CSS can be specified by the following six methods: |
|
| 5. |
What are pseudo-elements? Explain with an example. |
|
Answer» The :FIRST-LINE pseudo-element is used to style the first FORMATTED line of a paragraph by using text-transform PROPERTY with value uppercase. |
|
| 6. |
What are CSS combinators? |
|
Answer» The aspect ratio is defined as the ratio of WIDTH media feature to the ratio of height media features W:H. And the aspect ratio 16/9 is 42:32. The below Media QUERY ALLOWS to target the media query based on device-aspect-ratio which is 16/9. @media screen and (device-aspect-ratio: 16/9) { /* Your CODE here */ } |
|
| 7. |
<!-- Question --> <div id="outer"> <div id="inner"></div> </div> |
|
Answer» Conditional comments are developed by MICROSOFT. And it only worked with IE browser. The conditional comments HELP to target IE browser & comments can be written to target the different version of IE 5-IE 9. CSS rules or code embedded INSIDE of the comments will be used by Internet explorer based browser. WHEREAS from IE10 & above the support for conditional comments has been dropped. <p class=“conditional-comments“> <!--[if IE]> According to the conditional comment this is IE<br /> <![endif]--> <!--[if !IE]> --> According to the conditional comment this is not IE 5-9<br /> <!-- <![endif]--> </p> |
|
| 8. |
Write the style to display inner div in center for the below HTML code? |
|
Answer» In CSS, RULE sets are the complete COMPOSITION of WRITING a style to an element. Which comprises of selector along with a pseudo-class or a pseudo-element, declaration block with style properties and values. |
|
| 9. |
How to draw a triangle using CSS? |
|
Answer» In CSS, SAY if you have two conflicting styles for an element, the browser should decide which one to apply and render. This is chosen by the browser-based on specificity. Specificity is nothing but a set of rules. Some of the rules are mentioned below.
|
|
| 10. |
body { margin: 0; font-family: Arial; background-color: #f2f2f2; } .box { color: #fff; padding: 1em; text-align: center; background-color: #efefef; } .a { background-color: purple; } .b { background-color: violet; } .c { background-color: burlywood; } .d { background-color: gainsboro; } .layout { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; grid-template-rows: 100vh; } |
|
Answer» <P>In CSS, Gradients lets you display TRANSITION between two or more colors in a very smooth way. There are two types of Gradients in CSS3. 1. LINEAR Gradients – In CSS, a Linear gradient is a property VALUE which allows directions and stops colors. The direction goes in 5 different directions up, left, right, down and diagonal any one of the value can be used and for stop colors, there should be a minimum of 2 colors to be MENTIONED. We can even repeat the linear gradient. Ex: p {background-image: linear-gradient (direction, stop-color1, stop-color2, stop-color3)} 2. Radial Gradients – In CSS, a Radial gradient is a property value where the transition of the color will be defined from its center axis. By default, the shape would be an ellipse and the position would be in the center. Similar to linear gradients there should at least be two stop colors specified. Ex: p {background-image: radial-gradient (yellow, green, blue)} |
|
| 11. |
CSS |
|
Answer» Types of SELECTORS: Example: h1 [Selects all the elements with h1 tag.]
Example: #first-name [Selects the element having first-name as an ID value.]
Example: .blue [selects all the elements with a class name blue.]
Example: * [Selects all the elements in the document.]
Example: a [target = “_blank”] selects all the anchor elements with attribute value is _blank. |
|
| 12. |
<div class="layout"> <div class="a box">A</div> <div class="b box">B</div> <div class="c box">C</div> <div class="d box">D</div> </div> |
|
Answer» Pseudo-elements are used to style or modify the specific part of an HTML ELEMENT using CSS. Let us take an EXAMPLE and understand this better. Examples:
Here, in the above example to add the first letter to be in red we use the first-letter pseudo-element. For which the first letter of the paragraph will be in red color. In the next example, we have after and before in which while rendering the p tag. By default, we’ll have the content in the after pseudo-element DISPLAYED at the end of the p tag. Whereas when you hover on the p tag. We’ll have the content in the before pseudo-element displayed in the beginning as we have used hover pseudo-class. |
|
| 13. |
HTML |
||||||||||||||||||
|
Answer» Using a CSS selector ALONE is inefficient in some situations. So, CSS selectors become much more useful when we start combining them to perform a better selection. These relationships are indicated using CSS combinators. Below are examples of combinators.
|
|||||||||||||||||||
| 14. |
What will be the output of the following code having 4 divs having unique color and text and enclosed by single layout container class? |
|
Answer» /* Answer */ #outer { width: 300px; height: 300px; background-color: BLACK; position: relative; } #inner { width: 100px; height: 100px; background-color: red; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); } OUTPUT: We have a relative position to the outer div tag and absolute position for the inner div tag. In ORDER to PLACE the inner div in the middle. We used the top and left at 50%. Using top and left the box position starts from the middle of the top and left which not exactly in the center. So, in order to keep the inner div exactly at the center, we need to use transform, which helps US to place the inner div exactly at the center of the outer div. |
|
| 15. |
How to add the background yellow to paragraph element who has no children |
|
Answer» The basic idea to draw a triangle using pure CSS is using border of a BOX with zero HEIGHT and width. Let’s see the code below. <!-- HTML Code --> <div class="triangle"></div> /* CSS Code */ .triangle { height: 0; width: 0; border-top: 100PX solid transparent; border-bottom: 100px solid transparent; border-right: 100px solid red; }Using the basic idea, in the above code EXAMPLE, we have kept the width and height as zero, where the top and bottom borders are transparent and then the right border will be responsible to display the triangle in red color. You can event toggle them by having any two of the borders as transparent and the other border with a random color. Give a TRY. |
|
| 16. |
How can we center the container & everything inside a container both vertically and horizontally? |
|
Answer» The 4 child divs will be horizontally PLACED next to each other and will be of EQUAL WIDTH. |
|
| 17. |
div > pdiv + pdiv.p |
|
Answer» To add a BACKGROUND COLOR to paragraph element who has no children, we can use the FOLLOWING rule with :empty pseudo class. HTML <p></p> <p>Just</p> <p>Another world!</p>CSS p:empty { width: 100px; HEIGHT: 20px; background: whitesmoke; }Output |
|
| 18. |
How do you select all paragraphs inside a div element? |
|
Answer» HTML <div id='CONTAINER'> The Creative tension </div>#container { display: FLEX; align-items: CENTER; justify-content: center; BORDER: 1px dotted #c1c1c1; }Output |
|
| 19. |
How do you make a list that lists its items with lower greek symbol? |
|
Answer» <P>BASED on the DOM tree, the representation is div ELEMENT followed by PARAGRAPH element which is p, so the choice is (1) |
|
| 20. |
What is :focus-within? |
|
Answer» When the LIST-style-type:lower-greek symbol is USED, the list can be rendered as below.
|
|
| 21. |
What is object-fit:fill property and its other values? |
|
Answer» The :FOCUS-within PSEUDO selector in CSS, It selects an element if that element contains any CHILDREN that have :focus. For e.g. In a form element if there is an element which is CAPABLE to receive :focus, the :focus-within will be ACTIVE on form element. |
|
| 22. |
What is reflow in css? |
|
Answer» object-FIT is the property which handles the PICTURE based on the available width and height. Using fill value the aspect RATIO (Width:Height) will be maintained and image will not appear DISTORTED or squeezed, it will resized so that the longest of either the height or width can fit in the given dimensions. |
|
| 23. |
How to style scrollbar thumb for the webkit browsers? What are the components of scrollbar? |
|
Answer» The reflow can be imagined via water. As water fit itself according to the container it is poured into. It becomes the cup when poured in cup, if poured in a glass it BECOME glass. Similarly the CONTENT displayed on VARIOUS devices need to fit and reflow the content based on the device size. For example, by using media queries the page can be authored to reflow the content based on the device dimensions. The reflow of content is ALSO KNOWN as responsive web design (RWD). Reflow computes the layout of page. And it recomputes the position and dimension of the element. |
|
| 24. |
What are variable fonts, how it can be harnessed via css? |
|
Answer» The SCROLLBAR thumb is styled by pseudoclass ::-webkit-scrollbar-thumb A scrollbar is MADE of scrollbar buttons and a TRACK. The track is made up of track PIECES and a thumb. The track pieces refers to the AREAS above and below the thumb. |
|
| 25. |
Which css property can inform which properties associated with elements are about to be change during animation? |
Answer»
|
|
| 26. |
How to apply stroke and fill color to text? |
|
Answer» The will-CHANGE property inform the browser which properties are expected to change via css or by javascript
The ANCHOR will appear as below. With the css declaration .demo:hover the browser has been informed in advance that opacity will change and set up optimizations in advance. |
|
| 27. |
What is css paint api? |
|
Answer» To apply stroke on text and fill color, the property text-stroke and text-fill-color can be used with prefix. The same property with prefix (-webkit) is supported by edge, FIREFOX, chrome, safari and opera.
Output: |
|
| 28. |
How to manage paper bleed by css? |
Answer»
|
|
| 29. |
What is font-family -apple-system? |
|
Answer» The @page at-rule is used to SPECIFY the bleed area. It is a good PROPERTY to manage your content when the medium is based on print. The bleed is the part on the side of a DOCUMENT that gives the PRINTER a small amount of space. @page { bleed: 1cm; } |
|
| 30. |
How to select all immediate div which is the descendant of class cw-alert, whereas the descendant div with class name .alert-button-container not to be selected. The css rules to applicable for languages who text-direction is right to left? |
|
Answer» The font family system is proposed by apple in 2015, available with prefix as -apple-system The IDEA behind is to allow the WEB author to MAKE use of native fonts available on different platform running the browser. The font-family system is platform-specific rather browser specific. The same browser running on different platform/operating system will implement the GENERIC font differently as available on that platform. body { font-family: -apple-system, BlinkMacSystemFont, “Segoe UI”, ROBOTO, Helvetica, Arial, sans-serif; }For more: https://lists.w3.org/Archives/Public/www-style/2015Jul/0169.html |
|
| 31. |
How to invert the color of an image? |
|
Answer» To SELECT language text DIRECTION the selector will be [dir=rtl] and followed by class .cw-alert, and to select the DIV EXCEPT class .alert-button-container :not pseudoclass can be used as follows. [dir=rtl] .cw-alert>div:not(.alert-button-container){ /* Your code here */ } |
|
| 32. |
What are counters? |
|
Answer» CSS has filters which can PERFORM complex OPERATION on raster images and svgs. It gives tremendous power to css author to perform these operation in browser dynamically. invert()css FUNCTION invert the color of input image. FILTER: invert(1); |
|
| 33. |
Which is the difference between border-box and content-box Which box model is more in accordance with w3c box model? |
|
Answer» CSS Counters are similar to variables. It allows to number a list of element. It can be used in various ways to dynamically manage the information with sequential number with prefix or suffix content. It is a great addon for css authors if they are working on a content which include table of content, chapters heading and the numbering is been prefered to be HANDLED by dynamically, rather fixing the NUMBERS manually at each location/line in the code. |
|
| 34. |
How to manage the div visibility during 3d transform? |
|
Answer» <P>The difference between the two lies how the effective width of the container is calculated. The border-box & content-box belong to box-sizing property. The box-sizing property tell the browser how the effective width of the container to be calculated. content-box is based on DEFAULT css box sizing behavior. The RENDERED width of the container will include the container width+padding+border. Whereas the border-box tell the browser to include the padding & border values with-in the declared width for e.g. 200 PIXELS. So, the rendered width will be 200 pixels only. So, If you see in terms of historical perspective it behave as the earlier version of internet explorer box model whereas as the content-box is based on W3C box model computation. Code example
|
|
| 35. |
How to style hyperlinks which are relative or internal to a webpage? |
|
Answer» The visibility of the div during 3d transform can be managed via backface-visibility:hidden This property set the visibility as whether to show or HIDE the back face of an ELEMENT during 3d transform. Example from code:
|
|
| 36. |
What is the difference between position:sticky and position:fixed? |
|
Answer» We can do a PATTERN match for such urls by using the FOLLOWING syntax a[href^="/"], a[href^=".."] { /* WRITE your STYLES here */ } |
|
| 37. |
How many selector types exists in CSS? |
|
Answer» The element with position:fixed property will be displayed at the SPECIFIC offset (top, BOTTOM, LEFT and RIGHT) based on the position relative to the viewport. It will stay at same place when the page is scrolled. Whereas in position:sticky the element behave as relatively positioned element and once the containing block of the element crosses a specified threshold value it act as position:fixed element. So, the element switches its position based on the threshold value specified by top, bottom, left & right co-ordinates value. |
|
| 38. |
How to declare variables in CSS? |
| Answer» | |
| 39. |
How to style label associated with the selected radio input and checked checkboxes? |
|
Answer» CSS variables enables DEVELOPERS to reuse the code, once the variable are defined and it can be reused effectively, which gives good CONTROL over stylesheet in TERMS of code readability, maintenance and bring consistency. The variables which are declared in :root pseudo-class act as global CSS variables. We can DECLARE the variable via :root pseudo-class and reusing the variable using var followed by variable name in PARENTHESIS and assigning to CSS property. The class .foo and .bar will have the text color in red, the declared variable |
|
| 40. |
Define a two column layout using flexbox? |
|
Answer» We can use the CSS pseudo-class property :CHECKED on input type radio & checkbox and the adjacent SIBLING COMBINATOR (E + F) E is the first element which is input type radio or checkboxes and F is the NEXT element which is label. CSS /* E + F */ /* Selected radio input & label */ input[type=radio]:checked+label{ /* Your styles here */ } /* Checked checkbox input & label */ input[type=checkbox]:checked+label { /* Your styles here */ } |
|
| 41. |
Which one of [ID, class] selector has higher priority? |
|
Answer» We can define a two column LAYOUT using a CONTAINER and two divs inside the container by the following code. The parent container (.row) will have display: flex property. And the column will have flex VALUE 50%, which will divide the available width from the parent in two equal halves. Code example:
|
|
| 42. |
Draw a circle using CSS? |
|
Answer» In CSS, ID is suggested to be unique for an element whereas the class name is can be the same for many elements. As the ID is unique for the element, ID has higher priority than class in CSS. Consider the below example for better UNDERSTANDING. <!DOCTYPE html> <html> <head> <style> #rcorners { border-radius: 50%; background: #FF0000; border: 3px solid black; PADDING: 20px; WIDTH: 200px; HEIGHT: 200px; } .corners-div { border-radius: 50%; background: #73AD21; padding: 1px; width: 20px; height: 20px; } </style> </head> <body> <div id="rcorners" class="corners-div"></div> </body> </html>OUTPUT: For the above example, we still see the background color like red with the black border as output even after trying to override the background color as green without a border using the class selector below. This clearly answers our question that ID has a higher priority than class. |
|
| 43. |
In an HTML page there are two <input> elements with default values; one is editable and the other one not editable. Add cyan as the background color for the input element which is not editable using CSS. [Hint: Use pseudo-class] |
|
Answer» The easiest way to draw a circle in CSS is using border-radius property. The code below will display a circle. <!DOCTYPE html> <html> <head> <style> #rcorners { border-radius: 50%; background: #73AD21; border: 3px solid BLACK; padding: 20px; width: 200px; HEIGHT: 200px; } </style> </head> <body> <div id="rcorners"></div> </body> </html>OUTPUT: Make sure you have the same width and height and have border-radius as 50% which will display a circle as SHOWN above. |
|
| 44. |
What is a pseudo-class? Explain with an example? |
|
Answer» For the above SCENARIO, we NEED to use a pseudo-class to achieve this. pseudo-class is a special keyword which is added to a selector which specifies the state of the element. There are around ~60 pseudo-classes available. We use: read-only pseudo-class here in order to achieve selecting the right element and to make the selector only select the not editable one. /* :read-only pseudo-class is USED for the input element */ input:read-only{ background: cyan; }From the above code, we can SEE that we have used the input selector to select the input element, and the: read-only pseudo-class TARGETS the required element. And the cyan color is added using background property. |
|
| 45. |
what do you mean by shorthand notations in CSS3? |
|
Answer» A pseudo-class is a special keyword which is added to a selector which specifies the state of the element. There are around ~60 pseudo-classes available. Some of the relevant examples of pseudo-classes are ACTIVE, checked, disabled, empty, first-child, hover, focus, in-range, invalid, last-child, nth-child, optional, read-only, target, valid, VISITED, root, required which can actually be used to apply styles. /* COLOR changes to Brown on Hovering on anchor tag */ a:hover{ color: brown; } /* Color changes to Red on clicking on anchor tag */ a:active{ color: black; } /* Color changes to red after visiting on anchor tag */ a:visited { color: red; }In the above example for anchor tag where: visited, hover and: active are used specify the state of the anchor tag and depending on the pseudo-classes the specific styles will be applied. By default, the color of the anchor tag will be BLUE, on hovering on the anchor tag the color will change to blue, on clicking on it when it activates the color will change to black and after clicking for the REMAINING period of time the color of the anchor tag will be in red. |
|
| 46. |
Describe the box model in CSS3? |
|
Answer» Shorthand notations are also called as shorthand PROPERTIES in CSS. That lets you set multiple VALUES of CSS properties simultaneously. It’s often good to use shorthand notations because it reduces the file SIZE and even improves the performance. /* Example */ .border{ border-width: 1px; border-style: solid; border-COLOR: #000; } /* shorthand property for the above border example */ .border{ border: 1px solid #000; }In the above example, we can see that for a border class we have written three different properties of a border (width, style, and color). Which can be written in a better way by just mentioning border and GIVING all the required values (width, style, and color). This helps in reducing the file size and even increase the performance. Similarly, there are shorthand notations for many CSS properties one of the other examples is padding and margin properties. Which takes four different values sequentially and assigns each in the clockwise direction (Top, Right, Bottom, and Left). |
|
| 47. |
Difference between serif and sans-serif fonts? |
|
Answer» All the elements of HTML are boxes. In CSS we use the term box model when we TALK about the designs and layouts of the HTML elements. The CSS box model consists of MARGINS, border, padding, and CONTENT.
From the above figure, we can clearly understand that the element as a box and the meaning of all other PROPERTIES of a box model. It’s always important to know the meaning of all the properties and how they behave and where exactly they occupy the space to become a better CSS developer. |
|
| 48. |
How many ways can a color be specified in CSS3? |
|
Answer» Serif and sans-serif are the parent fonts to all the available fonts. Serif fonts usually have a hook (commonly known as feet) for all the letters, whereas in sans-serif (sans MEANS without in French), we will not have those hooks. From the above image, we could CLEARLY see that for the first ‘F’ I have hooks which are highlighted by circles and these are also called as feet. Whereas, we don’t have the feet in the second ‘F’. It’s important to always know which font-family that font which you are using belongs to. Some of the EXAMPLES of popular serif fonts are TIMES New Roman, Bookman, Baskerville, CAMBRIA, Courier, Century, Copper Black, Minion, and New York. Some of the examples of popular sans-serif fonts are Arial, Calibri, and Comic Sans, Helvetica, Geneva, San Francisco, and Ubuntu. |
|
| 49. |
What do you mean by selectors in CSS3? |
|
Answer» In CSS3 the VALUE for a color property can be given in the below-mentioned ways.
|
|
| 50. |
In how many ways can a CSS be written for an HTML file? |
|
Answer» Selectors are used to SELECTING the content which you want to add styles too. There are five TYPES of selectors in CSS. 1. Type Selector (Element Selector): selects all the elements which MATCH the given type. Example: h1 [Selects all the elements with h1 tag.] 2. ID Selector: selects the element which matches the ID value. It’s suggested that there should be only one element for a given ID. Example: #first-name [Selects the element having first-name as an ID value.] 3. Class Selector: selects all the elements which match the given class name. Example: .blue [selects all the elements with a class name blue.] 4. Universal Selector: selects all the elements in the DOCUMENT. Example: * [Selects all the elements in the document.] 5. Attribute Selector: selects the element which matches the attribute value. Example: a [target = “_blank”] selects all the anchor elements with attribute value is _blank. 90% of the times we use class selectors to apply styles. Only for specific conditions, we use other selectors. It’s better to use class selectors to apply styles for similar elements like labels in a form. |
|