Css Interview
Css Interview
Ans: CSS (Cascading Style Sheet) is used to style html elements , we can
arrange our html element by using css.
CSS Types
1. Inline css
2. Internal css
3. External css
Inline CSS: Inline CSS can style one element at a time. It is written in html tag
as a attribute.
Example:
<p style=”color:red”>hello inline css</p>
Internal CSS: Internal CSS can style multiple element at a time but in a single page. It is
written under the head tag by using style tag, to use internal css we need css selector to
select the html element.
Example:
<style>
P
{
color:red;
}
</style>
External CSS: External CSS can style multiple elements in a multiple pages. It is written in
separate css file, mostly web designer uses this css to design websites because it saves
our time and line of code. To use this css we have to link css file in a html page.
Example:
<link rel=”stylesheet” href=”css/style.css”>
Q2. Which CSS Type should be used
to design Website?
Ans: External CSS should be used to design a website because by using external css
we can style multiple elements in a multiple pages so it saves our time and line
of code.
Q3. Define any 5 Mostly used CSS Selector?
Ans: The most common CSS Selectors are following:
Element Selector: It select element by their name. like p,h1,li etc tag.
All Selector: It selects all the HTML elements. It is denoted by (*) asterisk
symbol.
Ans: CSS BOX Model Concept tells that you should (-) minus padding or
border value from width and height. If we don’t minus then it increase our
box size. CSS Box Model introduced in CSS2.
To minus padding and border again and again in different elements is very
boring work. So to get rid from this CSS3 introduced box-sizing:border-box
property.
• Download font from any website like google fonts, the fonts etc.
• Save the font in your fonts directory of the project.
• Write down the following code in your css file:
@font-face {
font-family: fontfamily; // you can write the name whatever you want
src: url(foldername/font-name.ttf); // here write the font path and font name with its
extension
}
body
{
font-family: fontfamilyname; // font family which you have created in your @font-face
property.
}
Q7. Define CSS3 features?
Ans: CSS3 has many features some of them are following:
Box-sizing:border-box;
Css variable
Flex
Border radius
Object-fit
Grid
Masking
Animations
Transitions
CALC
Counters
Gradients
Q8. Flex in CSS?
Ans: Flex is an advanced version of float we can align element horizontally
and vertically also. Flex is applied on parent element.
In flex there are two main properties:
Example:
.main
{
display:flex;
Justify-content:center;
}
Align-items: It is used for vertical alignment. It has the same properties as justify-
content have.
Example:
.main
{
Display:flex;
Align-items:center;
}
Q9. Pseudo Elements in CSS?
Example:
.abc
{
opacity:0.6;
}
rgba(): is used to transparent element. It applies to the selected
element only it does not apply to the child element.
Example:
.abc
{
background:rgba(0,0,0,0.6);
}
• Absolute: It free the element means you can move the absolute element
wherever you want to move on the web layout. Some examples of
absolute : dropdown menu, a box which is half on the other div.
CSS Variable is useful to hold the css property which is globally used in a website like color
scheme, font family, font size of content.
Example:
:root
{
--red-color:#f00;
--grey-color:#ddd;
}
.abc
{
background:var(--red-color);
width:300px;
height:300px;
}
.abc h2
{
color:var(--grey-color);
}
<div class=”abc”>
<h2> hello css variable</h2>
</div>
Q14. Image sprites?
Ans: Image sprites is very useful when we want to use number of small icons or images on a
website. Actually when we use number of small image on a website it increases http request
or in simply way we can say that is slows down our website.
So the solution is image sprite, image sprite is a single big sheet in which all the small icons
arranged. This is done by graphic designer, after that we use this sheet as a background
image on a website.
Example:
.fb
{
Background-image:url(‘images/social.png’);
Width:100px;
Height:100px;
}
.tw
{
Background-image:url(‘images/social.png’);
Width:100px;
Height:100px;
Background-position:-100px 0;
}
Here in this example you can see we have used same image on two different classes with background position.
Note:
To create sheet for image sprite all the icons have same size and on equal distance.
Q15. Animation in CSS?
Ans: Animation is used to give motion in a design to make attractive website to attract
users. Animation introduced in CSS3.
Example:
@keyframes colorchanger
{
from{background:#f00}
to{background:#000}
}
.box
{
width:300px;
height:300px;
background:#f00;
animation-name:colorchanger;
animation-duration:2s;
animation-iteration-count:infinite;
}
@keyframes is a reserved keyword, it is used to create animation, in this we can give from and to
or number of steps by using 0%,20%,100% etc.
To use animation we write the following:
animation-name : write the animation name which you have created.
animation-duration: write the duration of animation.
animation-iteration-count: write the number of counts how many times you want to run
animation.
Q16. 2D Transform and 3D Transform?
Ans: 2d transform is used to give motion effect on a website on mouse over or to create
creative design like rotate an element, scale an element, or move an element x axis or y
axis. 2d Transform introduced in CSS3.
rotate(deg): rotate is used to rotate an element. we can give flip effect on element by using
rotate() or rotate()
Example:
.box
{
transform: translate(0.-100px);
}
Q17. Display Property in CSS?
Ans: CSS has the following display property:
<li>blog</li>
</ul>
</div>
.main ul li
{
float:left;
}
<li>blog</li>
</ul>
</div>
.main>ul>li
{
float:left;
}
In this example It will only select the first ul of li, it will not select the subchild li.
Q20. What is Media Query, How to
Use it.
Ans: Media query is used to manage your design
on different size of device like mobile,ipad,
mobile horizontal view etc.
How to Use:
In media query there are some size which you
have to keep in mind , which are following:
Mobile Vertical Sizes:
1. 768px to 1024px
820px to 1120px
Example:
@media(max-width:360px)
{
}
@media(max-width:767px)
{
}
21. What is CSS Specificity?
.myclass {
background-color: gray;
}
p{
background-color: red !important;
}
</style>
</head>
<body>
</body>
</html>
Q23. z-index in CSS?
Ans:
When elements are positioned, they can overlap
other elements.
The z-index property specifies the stack order of
an element (which element should be placed
in front of, or behind, the others).
An element can have a positive or negative stack
order: