CSS Interview Questions and Answers
CSS Interview Questions and Answers
CSS Interview Questions and Answers
DEVELOPER UPDATES
CSS INTERVIEW QUESTIONS AND ANSWERS
What is CSS?
CSS (Cascading Style Sheet) is a simple design language used to
describe the look and formatting of a document written in a
markup Language. It is combined with markup languages i.e.
HTML & XHTML.
Using CSS we can change the color of the text, font styling,
layout designs, add/ reduce spacing, add different effects for
different devices and screen sizes and many more formatting.
What is Stylesheet?
A stylesheet is used to build a consistent, transportable and
well-designed style template. It describes the look and
formatting of the document.
What is the latest version of CSS?
CSS basically consists of many drafts for upcoming Standards.
CSS3 is the latest version of CSS. It helps you to control the
styling of the website.
Explain the new features in CSS3.
CSS basically consists of many drafts for upcoming Standards.
CSS3 includes some new features like New Selectors, CSS
Variables and functions, Gradients, Opacity, Transitions,
Transformation, Animations, FlexBox, Grid, and Media Queries.
Explain Different Types of Selectors
CSS selectors are used to find the particular HTML element
which you want to style or represent it in a different form.
Disadvantages:
1. External documents need to be imported that carry different
styles information.
2. To render your document you need to load external CSS first.
What are the advantages and disadvantages of an
embedded stylesheet?
Advantages:
Classes can be created to use on various HTML tag types in
the document.
Selector and grouping methods can be used to apply styles
under complex contexts
No additional downloads necessary to receive style
information
Disadvantages:
This method can not control styles for multiple documents
at once
Explain gradient with example
CSS Gradient basically represents a transition between two or
more colors. It is a very important aspect to beautify and add
them to your content.
2. vw(viewport width)
Represents 1% of the current width of the viewport.
Padding
Content
Margin Element(div,span,p,etc)
z-index: 2
z-index: 3
z-index: 2
z-index: 3
z-index: 4
This is done by designing and coding the site so that its layout,
images, and other parts change automatically to fit the size of
the screen being used to view it.
There are two main ways to do this: using keyframes and using
transitions.
keyframe name
1.EM:
The percentage of em is relative to the font-size of the parent
element.
2. REM:
REM stands for Root EM, meaning it's relative to the root
element of the page (usually HTML).
For instance, let's say you want to create a container that will
occupy 50% width of the window. If you set the width to 50rem,
it will occupy 50% of the width of the viewport.
Key differences:
On the other hand, REMs are a better option if you need to size-
up structural elements like margins or padding based on the
root font-size.
DEVELOPER UPDATES 21
WWW.DEVELOPERUPDATES.COM
CSS INTERVIEW QUESTIONS AND ANSWERS
2. inline:
It's like a word in a sentence. It takes up only as much width as it
needs and doesn't start on a new line.
3. inline-block:
A combination of the above two. It's like a box (like block), but it
doesn't take the full width and doesn't necessarily start on a new
line (like inline).
display: block;
display: inline;
DEVELOPER UPDATES 22
WWW.DEVELOPERUPDATES.COM
CSS INTERVIEW QUESTIONS AND ANSWERS
Thankfully, with the evolution of CSS, there are now several ways
to achieve this.
1. Using Flexbox:
Flexbox is a CSS layout module that makes it easier to design
complex layout structures with a more intuitive and clean
syntax.
DEVELOPER UPDATES 23
WWW.DEVELOPERUPDATES.COM
CSS INTERVIEW QUESTIONS AND ANSWERS
DEVELOPER UPDATES 23
WWW.DEVELOPERUPDATES.COM
CSS INTERVIEW QUESTIONS AND ANSWERS
Ensure that the parent of the .center-div has a position other than
static
If you know the width and height of the div, you can center it using
margin: auto and absolute positioning.
DEVELOPER UPDATES 24
WWW.DEVELOPERUPDATES.COM
CSS INTERVIEW QUESTIONS AND ANSWERS
Margin
Border
Padding
Content
Let's say you have a div element, and you style it like this:
DEVELOPER UPDATES 25
WWW.DEVELOPERUPDATES.COM
CSS INTERVIEW QUESTIONS AND ANSWERS
So, the total width = content + left padding + right padding + left
border + right border = 100px + 10px + 10px + 5px + 5px = 130px.
Note: Margin does not add to the width/height of the box itself.
Instead, it affects how far this box is from other elements.
DEVELOPER UPDATES 26
WWW.DEVELOPERUPDATES.COM
CSS INTERVIEW QUESTIONS AND ANSWERS
3. By Validating CSS:
Use online tools like the W3C CSS Validator to check for
errors in your stylesheet.
4. Use a Reset or Normalize CSS:
Browsers have default styles that can differ. Using a reset or
normalize.css ensures a consistent starting point across
browsers.
5. Browser Testing:
Different browsers can render CSS differently. Test your
website in various browsers (e.g., Chrome, Firefox, Safari) and
versions to ensure compatibility.
Tools like BrowserStack can help with this.
DEVELOPER UPDATES 27
WWW.DEVELOPERUPDATES.COM
Stay ahead with daily updates!
Follow us on social media for useful web
development content.
@richwebdeveloper
@new_javascript
@developerupdates
@developerupdates
@_chetanmahajan
Download on Gumroad
WWW.DEVELOPERUPDATES.COM