Interview FAQ CSS3-FAQ

CSS3 Interview Questions with answers

CSS3 is used to style a web page. This article cover the questions about css classes, selectors, properties that are frequently asked in an interview.

How to apply style on class?

By using dot(.)className style can be applied to a class

<div class="text-black">This is a text.</div>
<style>
.text-black {
    color:#000;
}
</style>
How to apply style on ID?

By using #idName style can be applied to ID

<div id="item1" class="text-black">This is a text.</div>
<style>
#item1 {
    background-color:#f00;
}
</style>
Id or class which have more preference?

Id has more preference.

What do you mean by Nesting of Class?

Classes can be nested. For example

 body .h1  {
font-size:36px;
}
What are the properties of Id?
  • It should be unique on entire web page.
  • there must not be special symbol in the id name except hyphen or underscore
  • First character of id name can’t be number.
Naming Convention for Class Name
  • First character can’t be number
  • Hyphen & space allowed only from special character
How to add CSS on a web page?

Inline : via style attribute on tag

<h1 style="color:black">Black</h1>

Internal/embedded : via style tag

<style>
h1{
color:black;
}
</style>

External : write all the style in style.css file and embed it onto the web page via link tag.

<link href="css/style.css" rel=stylesheet>
What are pseudo classes?

pseudo class is special keyword that is attached to selector to define its special state.

selector:pseudo-class {
  property:value;
} 

commonly used pseudo classes are

:hover
:active
:focus
:not
:first-child
:last-child
:before
:after
:first-of-typpe
:last-of-type
:link
:nth-child
:disabled
:visited

What is nth-child?

It is pseudo class and is used to select nth-element. For example

 ul li:nth-child(odd) or  ul li:nth-child(2n+1) 
 :nth-child(3n+4) 
What is CSS framework?

CSS framework provides basic structure of grid, form elements, icons, button, tab, drop-down etc.
For example: Bootstrap framework is widely used as CSS framework.

What are the advantage and disadvantages of embedded style-sheet?

Pros : No external download is required.

Cons : It is not possible to manage the style for different documents using one file.

What are the priorities of external, inline, internal/embedded?

Priority of styles:
Inline
Internal
External

What is CSS selector?

CSS selectors are used to find the element that needs to be applied style on it.
CSS has following type of selectors:

Element Based

a{
color:#000;
}

class based

.color-black{
color:#000;
}

id based

#black{
color:#000
}

pseudo class

a:hover{
text-decoration:none;
}

attribute selector

a[target="_blank"]{
color:#ccc;
}

combination selector
div > p : to select all the child p tag of div
div+p : to select immediate sibling of div tag
div ~p : to select all the siblings of div tag

What does background fixed property do?

background-attachment : fixed

What is universal selector?

star(*) is universal selector

How to write CSS syntax?
selector{
property: value;
}
What is the difference between CSS2 and CSS3?

Following features has been added into CSS3

Models : for example media queries , grid template, fonts etc.

CSS properties : eg. box-shadow, text-shadow, animation, transition, transform, gradient, background properties etc.

Name some CSS animation properties.
 /* @keyframes duration | timing-function | delay |  iteration-count | direction | fill-mode | play-state | name */ 
animation: 3s ease-in 1s 2 reverse both paused slidein; 

animation properties

Reference : For more go through this article here.

What is the difference between visibility hidden and display none?

Visibility hidden means : element will be no longer appear on web page but take its space.

Display none means : element will be no longer appear on web page as well as it will not take its space.

What is Box model?

The box model of CSS has
content box : area where content is displayed.
padding box : inner space of content box , basically space around content
border box: space for border .
margin box : outer space of content box

How to make horizontal or vertical scroll?
overflow-x: scroll // horizontal scroll  
overflow-y : scroll // vertical scroll  
overflow:hidden //hide scroll
What does z-index property do?

It defines the stack order of element. Higher the z-index is higher its stack order. It works only with position property.

What is media queries ? media types?

It is CSS query that returns true or false on the basis of all the expressions & media types used in it.

 @media not|only mediatype and (expressions) {
  CSS-Code;
}

4 types of media types
screen : for computer screen, tablets etc.
print : for printer
all : for all types
speech : for screen readers

Define some font properties?

font-weight:
font-style:
font-family:

What is RGB and Hexadecimal?

Both are color codes.

Is CSS case-sensitive?

CSS is case in-sensitive. But HTML class or ID is case sensitive.

What are some limitations of CSS?
  • Variables can not be used in CSS.
  • No logical condition can be applied using CSS
How to apply CSS gradient?
 background: linear-gradient(direction, color-stop1,  color-stop2, ...); 
 .gradient {
  background: linear-gradient(to right, red 5%, yellow 95%);
} 
 #gradient {
  back: linear-gradient(45deg, red, black);
 } 
 #gradient {
  background: radial-gradient(red 5%, yellow 15%, green 60%);
} 
How to vertical align image & content without flex?

Using display: table to main div and display:table-cell ; vertical-align:middle to both the divs.

How to include fonts via CSS?

using @font-face rule

 @font-face {
font-family:   webfont ;
src: url('mywebfont.eot'); /* IE9 Compat Modes */   src: url('mywebfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */        
url('mywebfont.woff2') format('woff2'), /* Super Modern Browsers */ 
url('mymwebfont.woff') format('woff'), /* Pretty Modern Browsers */        url('mywebfont.ttf')  format('truetype'), /* Safari, Android, iOS */        url('mywebfont.svg#svgFontName') format('svg'); /* Legacy iOS */ 
 }
 
 body {
     font-family:  railway ;
 } 
What are CSS units?

px : fixed unit
em: relative to parent and 1em = 16px
rem : relative to root element and 1rem = 16px
% : relative to parent element
vw : relative to viewport’s width
vh : relative to viewport’s height

What does important keyword do?

If and element property has !important keyword than it has more priority as compared to other styled.
for eg,
p {
font-size: 12px !important
}
p{
font-size: 13px;
}

then the font size will be 12px;

Name CSS transform properties?
transform: rotate(90deg); 
transform: skewY(30deg); 
transform: scale(1.1); 
How to apply CSS animations using keyframes?
@keyframes slidein {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

can be used as

 animation: 3s ease-in 1s 2 reverse both paused slidein;  

Reference : For more go through this article here.

What is W3C?

According to wikipedia
The World Wide Web Consortium is the main international standards organization for the World Wide Web. Founded in 1994 and currently led by Sir Tim Berners-Lee, the consortium is made up of member organizations which maintain full-time staff working together in the development of standards for the World Wide Web

Name some CSS functions?

calc()
rgb()
rgba()
liner-gradient()
radial-gradient()

How to include CSS on basis of media queries?
 <link rel="stylesheet" media="mediatype and|not|only (expressions)"  href="css/responsive.css">  
How many types of CSS positions are there?

Fixed
Relative
Absolute
Fixed

If you like this article you may want to read about the bootstrap framework which is widely used in creating front end of websites. Also you may look at JavaScript, JavaScript with oops etc. If you find this article useful please leave your feedback.

Leave a comment