CSS Questions
CSS Questions
1. What is CSS?
● Answer: CSS stands for Cascading Style Sheets. It's a language used to style HTML
elements, controlling their appearance on web pages (colors, fonts, layout, etc.).
8. What is the difference between display: block, display: inline, and display:
inline-block?
● Answer:
○ display: block:
■ Starts on a new line.
■ Takes up the full width of its parent container.
■ Can have margins and padding on all sides.
○ display: inline:
■ Does not start on a new line.
■ Only takes up the width of its content.
■ Margins and padding only affect the horizontal space.
○ display: inline-block:
■ Combines properties of block and inline.
■ Does not start on a new line.
■ Can have margins and padding on all sides.
11. What is the difference between visibility: hidden and display: none?
● Answer:
○ visibility: hidden:
■ Hides the element but still occupies space in the layout.
○ display: none:
■ Hides the element and removes it completely from the document flow.
16. What are CSS preprocessors, and what are some examples?
● Answer: CSS preprocessors are languages that extend the capabilities of CSS by adding
features like variables, mixins, nesting, and more.
○ Examples: Sass, Less, Stylus.
● Answer:
○ Use the content property to add content to the pseudo-elements.
○ Use other CSS properties to style them like any other element (e.g., color,
font-size, background-color, position).
23. What are CSS filters, and what are some examples?
● Answer: CSS filters allow you to apply various visual effects to elements, such as:
○ grayscale: Converts the image to grayscale.
○ blur: Blurs the image.
○ sepia: Applies a sepia tone to the image.
○ invert: Inverts the colors.
○ saturate: Adjusts the saturation of colors.
● Answer: The overflow property determines how content that overflows the element's
box is handled.
○ visible: Content overflows without clipping.
○ hidden: Content is clipped and hidden.
○ scroll: Adds scrollbars to the element.
○ auto: Adds scrollbars only if the content overflows.
● Answer:
○ border-radius: Rounds the corners of an element's border.
○ border-image: Replaces the element's border with a specified image.
● Answer: The opacity property sets the transparency level of an element. A value of 1
is fully opaque, and 0 is fully transparent.
● Answer:
○ Use the background-image property with the linear-gradient or
radial-gradient functions.
● Answer: Flexbox is a one-dimensional layout model that gives you powerful control over
the alignment, sizing, and ordering of child elements within a container.
● Answer: Grid is a two-dimensional layout system that allows you to create complex
grid-based layouts with rows and columns.
31. What are some common CSS frameworks, and what are their benefits?
● Answer:
○ Bootstrap: A popular framework with a wide range of pre-built components and
responsive grid system.
○ Foundation: Another robust framework with a focus on accessibility and
responsive design.
○ Materialize: Inspired by Google's Material Design, offering a unique aesthetic
and interactive components.
○ Tailwind CSS: A utility-first framework that provides a large set of pre-defined
CSS classes for rapid development.
● Answer:
○ Minimize CSS files: Remove unnecessary whitespace and comments.
○ Use CSS sprites: Combine multiple images into a single image to reduce HTTP
requests.
○ Avoid excessive use of the !important rule.
○ Use browser caching to improve load times.
○ Consider using a CSS preprocessor for better organization and
maintainability.
● Answer:
○ Browser developer tools (e.g., Chrome DevTools, Firefox Developer Tools)
○ CSS Lint: A tool that checks CSS code for errors and potential problems.
● Answer:
○ margin: The space outside the border of an element.
○ padding: The space inside the border of an element.
● Answer:
○ Use a combination of HTML and CSS:
■ Create a container element for the dropdown.
■ Use the display: none; property to initially hide the dropdown
content.
■ Use JavaScript to show/hide the dropdown content when the user
interacts with the trigger element.
● Answer:
○ Use the max-width: 100%; property to ensure the image doesn't exceed the
width of its container.
○ Consider using the srcset and sizes attributes for responsive images.
● Answer: The text-decoration property adds decorative lines to text (e.g., underline,
overline, line-through).
● Answer:
○ overflow-x: Controls how content that overflows horizontally is handled.
○ overflow-y: Controls how content that overflows vertically is handled.
● Answer: The cursor property changes the appearance of the mouse pointer when it
moves over an element.
● Answer: The opacity property sets the transparency level of an element. A value of 1
is fully opaque, and 0 is fully transparent.
● Answer: The z-index property controls the stacking order of elements that overlap.
Higher z-index values appear on top of lower ones.
● Answer: The text-align property aligns the text within an element. Common values
include:
○ left: Aligns text to the left.
○ center: Aligns text to the center.
○ right: Aligns text to the right.
○ justify: Justifies text between the left and right margins.
● Answer: The text-transform property changes the case of the text. Common values
include:
○ uppercase: Converts text to uppercase.
○ lowercase: Converts text to lowercase.
○ capitalize: Capitalizes the first letter of each 1 word.
○ 1. github.com
○ github.com
○
● Answer: The line-height property sets the height of each line of text.
● Answer: The border-color property sets the color of the element's border.
● Answer: The border-width property sets the width of the element's border.
● Answer: The border-style property sets the style of the element's border (e.g.,
solid, dashed, dotted).
● Answer: The list-style property controls the appearance of list items. It can be used
to:
○ Change the type of bullet point (e.g., disc, circle, square).
○ Change the image used as a bullet point.
○ Remove bullet points entirely.
● Answer: The white-space property controls how white space within an element is
handled.
● Answer: The word-wrap property allows long words to be broken onto multiple lines.
● Answer: The text-overflow property controls how content that overflows the width of
an element is handled.
● Answer: The table-layout property controls how the width of table columns is
calculated.
66. What is the purpose of the content property (used with ::before and ::after)?
● Answer: The content property specifies the content to be inserted before or after the
specified element.
● Answer: The quotes property specifies the quotation marks to be used for block
quotes.
68. What is the purpose of the speak property?
● Answer: The speak property controls whether or not text should be spoken by screen
readers.
● Answer: The voice-family property specifies the voice to be used for speech
synthesis.
● Answer: The speak-date property controls how dates should be spoken by screen
readers.
● Answer: The speak-time property controls how times should be spoken by screen
readers.
● Answer: The text-align-last property controls the alignment of the last line of text.
● Answer: The text-justify property controls how text is justified between the left and
right margins.
● Answer: The hanging property controls whether or not the first line of text is indented.
● Answer: The text-overflow property controls how content that overflows the width of
an element is handled.
● Answer: The text-decoration property adds decorative lines to text (e.g., underline,
overline, line-through).
● Answer: The text-decoration-color property sets the color of the text decoration.
● Answer: The text-decoration-style property sets the style of the text decoration
(e.g., solid, dotted, dashed).
● Answer: The backface-visibility property controls whether or not the back face
of an element is visible.
● Answer: The transform-origin property sets the origin point for transformations.
● Answer: The perspective-origin property sets the origin point for the 3D
perspective.
● Answer: The transition property allows for smooth visual changes over time when
an element's CSS properties are modified.
● Answer: The animation property allows for more complex and customizable visual
effects, such as looping, multiple keyframes, and more control over timing.
● Answer: The will-change property tells the browser which properties of an element
are likely to change, allowing the browser to optimize performance.
● Answer: The backface-visibility property controls whether or not the back face
of an element is visible.
● Answer: The perspective-origin property sets the origin point for the 3D
perspective.
● Answer: The clip-path property allows you to clip an element to a specific shape.
● Answer: The mask property allows you to hide parts of an element using an image or a
shape.
111. What is the purpose of the filter property?
● Answer: The user-select property controls whether or not text within an element can
be selected by the user.
● Answer: The touch-action property controls how touch events are handled by an
element.
● Answer: The overflow property determines how content that overflows the element's
box is handled.
● Answer: The overflow-x property controls how content that overflows horizontally is
handled.
● Answer: The position property controls the positioning of an element within the
document flow.
● Answer: The top property specifies the top position of a positioned element.
● Answer: The right property specifies the right position of a positioned element.
● Answer: The bottom property specifies the bottom position of a positioned element.
● Answer: The left property specifies the left position of a positioned element.
● Answer: The z-index property controls the stacking order of elements that overlap.
● Answer: The float property removes an element from the normal document flow.
● Answer: The clear property prevents elements from overlapping floated elements.
● Answer: The margin property sets the space outside the border of an element.
● Answer: The padding property sets the space inside the border of an element.
● Answer: The border property sets the width, style, and color of the element's border.
● Answer: The border-width property sets the width of the element's border.