Explore topic-wise InterviewSolutions in .

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.

  • Selectors: Selectors are used to selecting the content which you want to add styles too. There are five types of selectors in CSS.
    • Type Selector (Element Selector)
    • ID Selector
    • Class Selector
    • Universal Selector
    • Attribute Selector
  • Rounded Corners: Using this feature, we can apply smooth corners to any element. The border-radius property is used to give the element smooth edges. Check out the example below for syntax and usage.
<!DOCTYPE html> <html>     <head>         <style>             #rcorner {                 border-radius: 25px;                 background: #73AD21;                 padding: 20px;                 width: 200px;                 height: 150px;             }         </style>     </head>     <body>         <div id="rcorner"></div>     </body> </html>
  • Border Image: border-image property allows us to use an image as a border. Check the example below for syntax and usage.
<!DOCTYPE html> <html>     <head>         <style>             #borderimg {                 border: 10px solid transparent;                 padding: 15px;                 border-image: url(border.png) 30 round;             }         </style>     </head>     <body>         <p id="borderimg">Lorem ipsum dolor sit amet consectetur adipisicing elit. Expedita ut esse, accusamus id totam ipsam voluptatum MAGNI. Aliquam, ipsa ipsum! Soluta optio quia recusandae qui sed suscipit. Dolorem, libero obcaecati.</p>     </body> </html>
  • Shadow: It’s an effect which can be applied to text and box. text-shadow and box-shadow are the property names used to added shadow to text and box respectively.
  • Transitions: CSS Transitions allows us to change the values of the transition property smoothly.
  • Gradients: We can directly use gradients in for two or more colors using linear-gradient and radial-gradient properties.
  • Grid Layouts: We have two new display properties which are grid and inline-grid which offers us a grid-based layout with similar rows and columns concept.
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;  }

3.

Explain Gradients in CSS?

Answer»

opacty is not a CSS PROPERTY.

4.

Mention types of selectors?

Answer»

Colors in CSS can be specified by the following six methods:

  •          Hexadecimal colors color: #000000;
  •          RGB colors color: rgb(100, 115, 220);
  •          RGBA colors color: rgba(0, 0, 1, 0.6);
  •          HSL colors color: hsl(34, 100%, 23%);
  •          HSLA colors color: hsla(34, 100%, 53%, 0.5);
  •          Predefined/Cross-browser color names color: burlywood;
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.

For e.g.

p:first-line { text-transform: 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.

&lt;!-- Question --&gt;     &lt;div id="outer"&gt;       &lt;div id="inner"&gt;&lt;/div&gt;     &lt;/div&gt;

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.

  1. Say- if you have two element selectors selecting the same element but having different styles. The element selector which is read LATEST by the browser will get APPLIED
  2. The element selector has less priority compared to a class selector. So, the styles WRITTEN in the class selector gets applied.
  3. The class selector has less priority compared to an ID selector. So, the styles written in the ID selector gets applied.
  4. If we use !important along with the value for a CSS property. This style gets applied no MATTER it’s a class or an element or an ID selector.
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:

  • TYPE Selector (ELEMENT Selector): selects all the elements which match the given type. 

Example: h1 [Selects all the elements with h1 tag.]

  • 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.] 

  • Class Selector: selects all the elements which match the given class name.

Example: .blue [selects all the elements with a class name blue.] 

  • Universal Selector: selects all the elements in the document.

Example: * [Selects all the elements in the document.]

  • Attribute Selector: selects the element which matches the attribute value.

Example: a [target = “_blank”] selects all the anchor elements with attribute value is _blank.

12.

&lt;div class="layout"&gt;   &lt;div class="a box"&gt;A&lt;/div&gt;   &lt;div class="b box"&gt;B&lt;/div&gt;   &lt;div class="c box"&gt;C&lt;/div&gt;   &lt;div class="d box"&gt;D&lt;/div&gt; &lt;/div&gt;

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:

  1. Styling the first letter of an element.
  2. Inserting the CONTENT before or after the element.
/* Styling the first letter of a p tag */ p::first-letter {     color: red; } /* Adding the content after p tag */ p::after{     content: "I'm added after the element"; } /* Adding the content before p tag */ p:hover::before{     content: "I'm added before the element" }

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.

Name
Syntax
Selects
Selector List
A, B
Selects the matching element A/B.
Descendant Combinator
A B
Selects any element matching B that is descendant of an element matching A.
Child Combinator
A &GT; B
Selects any element matching B that is the DIRECT child of an element matching A.
Adjacent Sibling Combinator
A + B
Selects any element matching B that is the NEXT sibling of the element matching A.
General Sibling Combinator
A ~ B
Selects any element matching B that is one of the next siblings of an element matching A.
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 &amp; 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 &gt; 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>

CSS

#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.

  • HTML 
&LT;ol> <li>Who</li> <li>When</li> <li>Where</li> <li>What</li> <li>How</li> <li>Why</li> </ol> li{   list-style-type:lower-greek }

OUTPUT

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.

Other values are cover, NONE, scale-down.

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»
  • The variable font is a single font, yet it can exhibit multiple appearance. It can be considered as evolution of Open TYPE fonts.
  • The permutation of appearance is stored in a single font and the file size may be larger than the traditional font.
  • It gives css authors to vary the size and appearance BASED on content and context while working with single font.
  • font-variation-settings provides low LEVEL control to modify the weight (THICKNESS), font stretch and other RELATED properties which are manipulated by axis of variation (identifiable by axis tag).
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

  • HTML
<a class='DEMO' href='#'>Demo url</a>
  • CSS
.demo {   transition: opacity .2s;   opacity: 1;   font-family: Arial, Helvetica, Sans-serif;   font-size: 35px;   font-weight: bold;   color: black; } .demo:hover {   will-change: opacity; } .demo:active {   opacity: .2; }
  • DEMO:

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.
And when the hyperlink is clicked, the TEXT will have 20% opacity during the transition.

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.

  • HTML
<DIV id="fill-stroke"&GT;   <h1>     Stroke &amp; Fill   </h1> </div>
  • CSS  
h1 {   font-family: Arial, Helvetica, Sans-serif; } #fill-stroke {   background-color: RGB(255, 255, 255);   color: rgb(102, 102, 102);   -webkit-text-stroke: 1.4px rgb(0, 0, 0);   -webkit-text-fill-color: rgb(46, 255, 60); }

Output:

28.

How to manage paper bleed by css?

Answer»
  • CSS paint API allows to PROGRAMMATICALLY GENERATE an image via css.
  • The author can create their own paint worklet which is written in javascript and that code can be used with background-image: paint(checkerboard).
  • The css paint api is STILL an evolving technology and google chrome is leading the pack AMONG the browser.
    https://ishoudinireadyyet.com/
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&GT;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 is also SUPPORTED by vast number of browsers IE, Edge, Firefox, Chrome, Safari & Opera. CSS counters can be USED to order  

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                

  • HTML
<div id="container-parent">   <p>I am a parent with two children. </p>   <div id="container-border-box"> <p>I am child with <code>box-sizing:border-box</code>&nbsp;&amp; i stay with in parent width limit.</p>   </div>   <br />   <div id="container-content-box"> <p>I am child with <code>box-sizing:content-box</code>&nbsp;&amp; i love to cross the parent width limit.</p>   </div> </div>
  • CSS
#container-parent {   width: 400px;   height: 300px;   border: SOLID 10px DodgerBlue;   margin: 0.8em; } #container-parent div {   width: 100%;   border: 10px solid SlateBlue;   padding: 5px; } #container-border-box {   box-sizing: border-box; } #container-content-box {   box-sizing: content-box; }

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:

  • HTML
<div class='container'>   <div class="card"> <div class="face front">    See </div> <div class="face back">    SAW </div>   </div> </div> .container {   position: relative;   margin: 12px 24px;   font-family:  system-ui, -apple-system, Arial, Helvetica, Trebuchet MS; }
  • CSS
.card {   width: 200px;   height: 50px;   position: relative;   transform-style: preserve-3d;   transition: 0.5s; } .container:hover .card {   transform: rotateY(180deg); } .face {   position: absolute;   backface-visibility: hidden;   top: 0;   left: 0;   width: 100%;   height: 100%;   COLOR: white;   line-height: 50px;   text-align: center;   border-radius:5px; } .front {   background: DodgerBlue;   z-index: 10; } .back {   transform: rotateY(180deg);   background: SlateBlue; } .container:hover .front {   z-index: 0; }

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 &AMP; right co-ordinates value.

38.

How to declare variables in CSS?

Answer»

There are 11 TYPES of selector, such as:

  1. UNIVERSAL 
  2. Element or Type selector
  3. ID
  4. Class
  5. Descendant combinator
  6. Child combinator
  7. General SIBLING combinator
  8. Adjacent Sibling combinator
  9. Attribute selector
  10. Pseudo-class
  11. Pseudo-element
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
--color has been reused via var (--color) in both of these classes.

:root {   --color: red; }   .foo {   color: var(--color) }   .bar {   color: var(--color) }
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:

  • HTML
<div class="row">    <div class="column">     Left column   </div>     <div class="column">     RIGHT column   </div>   </div>
  • CSS
.row {   display: flex;   width: 100%; }   .column {   flex: 50%;   border: 1px solid #ccc; }

OUTPUT

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 &lt;input&gt; 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.

  • MARGIN: Area outside the border is called a margin (Also called as outer area keeping the border as reference). The property to use margin in CSS is ‘margin’ which is a shorthand property will give the mentioned space in all the four sides equally. 
  • Border: The area that goes around the padding and content is called a border. The property to use the border in CSS is ‘border’ which is a shorthand will take the size of the border, the color of the border and type of the border as values sequentially.
  • Padding: The area around the content is called padding (Also called as Inner area keeping the border as reference). The property to use padding in CSS is ‘padding’ which is a shorthand property will give the mentioned space in all the four sides equally.
  • Content: It’s the actual content of the box model which contains text or image.

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.

  1. Predefined color names: ~140 color names are supported inCSS3. Examples like red, brown, blue, Aqua, Indigo, etc.,
  2. Hexadecimal values: The values are given in the format of #RRGGBB where RR is red, GG is green and BB is blue. The values are between 00 and FF.
  3. RGB values: RGB color value is specified using the RGB (red, green, blue) function. The RGB values are INTEGER values between 0 and 255 or percentage values between 0% to 100%
  4. RGBA values: RGBA color value is specified using the RGBA (red, green, blue, ALPHA) function. It’s similar to RGB value with an extra parameter called alpha which specifies the opacity.
  5. HSL values: HSL stands for hue, saturation, and lightness. HSL color value is specified with the HSL (hue, saturation, lightness) function. Hue is a degree on the color wheel (from 0 to 360). 0 (Zero) or 360 is red, 120 is green, 240 is blue. Saturation is a percentage value. 0% means a shade of grey and 100% is the full color. Lightness is also a percentage. 0% is black, 100% is white.
  6. HSLA values: HSLA color value is specified with the HSLA(hue, saturation, lightness, alpha) function. It’s similar to HSL values with an extra parameter called alpha which specifies the opacity.
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.