css
css
Answer: CSS (Cascading Style Sheets) is a style sheet language used for describing the
presentation of a web page, including its layout, design, colors, fonts, and spacing.
• Inline CSS (within the HTML element using the style attribute)
• Internal CSS (inside the <style> tag within the <head> section)
• External CSS (linked using the <link> tag to an external .css file)
Answer: The CSS box model defines the rectangular boxes generated for elements,
including:
• Content
• Padding
• Border
• Margin
Answer:
Answer: Specificity is a ranking system used to determine which CSS rule applies when
multiple rules target the same element. It’s calculated based on the type of selectors used
(ID, class, element).
6. What is the !important rule in CSS?
Answer: The !important rule is used to give a CSS declaration higher priority, overriding
any other styles, even if they have higher specificity.
Answer:
Answer: Pseudo-classes are keywords added to selectors that specify a special state of an
element, like :hover, :active, :focus, and :first-child.
Answer: The float property is used to position an element to the left or right, allowing
other content to flow around it.
Answer:
• display: none removes the element from the document flow entirely.
• visibility: hidden hides the element but still takes up space in the layout.
12. What is Flexbox in CSS?
Answer: Flexbox is a layout model that allows you to design complex layouts with ease. It
distributes space within a container and aligns content in both horizontal and vertical
directions.
Answer:
• absolute positions the element relative to its nearest positioned ancestor (non-
static).
• relative positions the element relative to its normal position in the document
flow.
Answer: CSS Grid is a two-dimensional layout system for the web, allowing you to create
complex grid-based layouts with rows and columns.
Answer: The z-index property controls the stacking order of elements. Higher z-index
values are stacked above lower values.
Answer: box-sizing: border-box includes padding and border in the element’s total
width and height, making it easier to manage layouts.
Answer:
• inline elements do not start on a new line and only take up as much width as
necessary.
• block elements start on a new line and take up the full width available.
• inline-block elements behave like inline elements but can have width and
height properties.
Answer: The @media rule allows for applying styles based on different conditions like
screen size, resolution, or device orientation, making designs responsive.
Answer: A CSS preprocessor (like Sass or LESS) allows you to write CSS more efficiently by
using variables, nested rules, mixins, functions, and more.
Answer: The transition property allows you to change property values smoothly (with
animation) over a given duration when a state change occurs.
Answer: Responsive design involves creating web pages that adapt to different screen
sizes and devices using flexible layouts, media queries, and fluid grids.
Answer: CSS animations allow elements to change properties over time, enabling
movement, transformations, and changes in appearance.
25. What is opacity in CSS?
Answer: The opacity property controls the transparency of an element, with a range from
0 (fully transparent) to 1 (fully opaque).
Answer:
• static (default)
• relative
• absolute
• fixed
• sticky
Answer: Use responsive design techniques like flexible layouts, fluid grids, and media
queries to adjust the layout for different screen sizes.
Answer: @font-face allows you to define custom fonts that can be loaded and used on a
web page, regardless of whether the font is installed on the user's device.
Answer: Media queries are used to apply CSS rules based on specific conditions, such as
screen width, device orientation, or resolution.
Answer:
Answer: vh stands for viewport height and vw stands for viewport width. 1 vh is 1% of the
viewport height, and 1 vw is 1% of the viewport width.
Answer: The box-shadow property adds shadow effects around an element’s frame, with
options for offset, blur, spread, and color.
Answer: The text-shadow property allows you to add shadow effects to text, with values
for horizontal and vertical offsets, blur radius, and color.
Answer: Set border-radius: 50% on the image, and ensure the width and height are
equal to create a circle.
Answer: The visibility property controls whether an element is visible or not, with
values like visible, hidden, or collapse.
39. What is the clip-path property in CSS?
Answer: The clip-path property defines a clipping region that determines which part of
an element is visible and which part is hidden.
Answer: Use position: sticky; along with top: 0; to keep a navbar at the top of the
viewport when scrolling.
Answer: inline elements do not start on a new line and only take up as much space as
their content, while block elements occupy the full width of their container.
Answer: You can group multiple selectors by separating them with commas. For example:
h1, h2, p { color: blue; }
Answer: ::before and ::after are pseudo-elements used to insert content before or
after an element's actual content.
45. What are position: fixed and position: sticky used for?
Answer: position: fixed keeps an element in a fixed position relative to the viewport,
while position: sticky toggles between relative and fixed, depending on scroll
position.
46. What is the opacity property in CSS?
Answer: The opacity property specifies the transparency level of an element, with values
from 0 (completely transparent) to 1 (completely opaque).
Answer: The text-transform property controls the capitalization of text, with values like
uppercase, lowercase, and capitalize.
Answer: Use the :hover pseudo-class to apply styles when an element is hovered over,
for example: a:hover { color: red; }
Answer: The cursor property specifies the type of cursor to be displayed when hovering
over an element, such as pointer, crosshair, or wait.
Answer: The transform property allows you to apply transformations to an element such
as rotating, scaling, or translating it in 2D or 3D space.