Question | Answer |
What is CSS? | CSS stands for Cascading Style Sheets. It is a styling language used to describe the look and formatting of a document. |
What are the different ways to include CSS in an HTML document? | CSS can be included in an HTML document using inline styles, internal stylesheets, and external stylesheets. |
What is the difference between inline and block elements? | Inline elements do not start on a new line and only take up as much width as necessary, while block elements start on a new line and take up the full width available. |
What is the box model in CSS? | The box model refers to the concept of how elements are structured in CSS, including content, padding, border, and margin. |
What are the different CSS selectors? | CSS selectors are used to select and style specific elements. They include element selectors, class selectors, ID selectors, and more. |
Explain the concept of specificity in CSS. | Specificity determines which CSS rule gets applied when multiple rules target the same element. It follows a specificity hierarchy based on selector types and their order. |
How can you center an element horizontally in CSS? | You can center an element horizontally by setting its margin property to “auto” and its display property to “block” or “inline-block”. |
What are pseudo-classes in CSS? | Pseudo-classes are keywords used to select elements based on specific states or actions, such as :hover, :active, :visited, and :focus. |
Explain the difference between margin and padding in CSS. | Margin is the space outside an element, creating a gap between elements, while padding is the space inside an element, creating space between the element’s content and its border. |
How do you include comments in CSS? | Comments in CSS can be added using /* */ syntax. They are ignored by the browser and are used for adding notes or explanations to the code. |
What is the CSS box-sizing property used for? | The box-sizing property is used to control how the total width and height of an element are calculated, including or excluding padding and border. |
What is the difference between absolute and relative positioning in CSS? | Absolute positioning is relative to the nearest positioned ancestor, while relative positioning is relative to the normal flow of the document. |
How do you group multiple CSS selectors? | Multiple CSS selectors can be grouped using a comma (,). This allows applying the same styles to different selectors simultaneously. |
What is the “float” property used for in CSS? | The float property is used to specify whether an element should float to the left, right, or none. It is commonly used for creating layouts with multiple columns. |
How can you hide an element visually but still have it available for screen readers? | You can use the CSS “display: none” property to hide an element visually, but it will still be accessible to screen readers. |
What is the purpose of the CSS z-index property? | The z-index property is used to control the stacking order of positioned elements. Elements with a higher z-index appear on top of elements with a lower z-index. |
How can you apply rounded corners to an element in CSS? | Rounded corners can be applied to an element using the “border-radius” property. |
What is a media query in CSS? | A media query is a CSS technique used to apply different styles based on the characteristics of the device or viewport, such as screen size, resolution, or orientation. |
How do you vertically align text in CSS? | Text can be vertically aligned within its container using the “vertical-align” property. However, it works differently depending on the element’s display property. |
What is the CSS “box-shadow” property used for? | The box-shadow property is used to add a shadow effect to an element. It allows specifying the shadow’s position, color, blur, and spread. |
How can you select the last child element in CSS? | The :last-child pseudo-class can be used to select the last child element of its parent. |
What is the difference between “display: none” and “visibility: hidden” in CSS? | “display: none” completely removes the element from the layout, while “visibility: hidden” hides the element but still occupies space in the layout. |
How can you make a background image fixed while scrolling the content? | You can make a background image fixed by using the “background-attachment” property with a value of “fixed”. |
What is the purpose of the CSS “transition” property? | The “transition” property is used to create smooth animations and transitions when applying changes to an element’s style. |
How can you vertically center an element in CSS? | You can vertically center an element by setting its parent container’s display property to “flex” and using the “align-items” or “justify-content” property with a value of “center”. |
How can you make an element’s width responsive in CSS? | An element’s width can be made responsive by using relative units like percentages or viewport-relative units like vw (viewport width). |
What is the CSS “opacity” property used for? | The “opacity” property is used to adjust the transparency of an element. A value of 1 is fully opaque, while a value of 0 is fully transparent. |
How do you apply a gradient background in CSS? | A gradient background can be applied using the “background-image” property with a value of “linear-gradient” or “radial-gradient”. |
What is the purpose of the CSS “transform” property? | The “transform” property is used to apply transformations like scaling, rotating, skewing, or translating elements in 2D or 3D space. |
How can you vertically align an element in the middle of the page? | You can vertically align an element in the middle of the page by setting its position to “absolute” or “fixed” and using the “top” and “transform” properties. |
What is the CSS “text-transform” property used for? | The “text-transform” property is used to control the capitalization or casing of text, such as making it uppercase, lowercase, or capitalized. |
How do you apply a hover effect to an element in CSS? | A hover effect can be applied to an element using the “:hover” pseudo-class. It allows specifying different styles when the element is hovered over. |
What is the purpose of the CSS “flexbox” layout? | The CSS “flexbox” layout provides a flexible way to create responsive layouts by distributing space among items in a container. |
How can you make a text element blink in CSS? | The “animation” property with the “@keyframes” rule can be used to make a text element blink by continuously changing its opacity. |
What is the CSS “overflow” property used for? | The “overflow” property is used to control how content that exceeds the element’s dimensions is displayed, such as scrolling or hiding the overflow. |
How do you create a fixed header that remains visible while scrolling? | A fixed header can be created by setting its position to “fixed” and specifying the desired dimensions. |
What is the CSS “grid” layout used for? | The CSS “grid” layout is a two-dimensional system used to create complex and flexible grid-based layouts. |
How can you change the color of a visited link in CSS? | The “a:visited” pseudo-class can be used to change the color of a visited link in CSS. |
What is the purpose of the CSS “pseudo-element” ::before and ::after? | The “::before” and “::after” pseudo-elements allow adding content before or after an element’s content, which can be styled independently. |
How can you hide an element visually but keep it accessible to screen readers? | You can use the CSS “clip-path” property with a value of “inset(100%)” to visually hide an element while still allowing screen readers to access it. |
What is the CSS “backface-visibility” property used for? | The “backface-visibility” property is used to control whether the back face of an element is visible when it is rotated or transformed in 3D space. |
How do you apply a gradient to a text element in CSS? | A gradient can be applied to a text element by using the “-webkit-background-clip” property with a value of “text” and specifying a gradient background. |
What is the purpose of the CSS “filter” property? | The “filter” property is used to apply visual effects like blurring, adjusting brightness/contrast, or adding color overlays to an element. |
How can you make an element responsive using CSS media queries? | CSS media queries can be used to apply different styles to an element based on the device’s characteristics, allowing for responsive design. |
How do you create a sticky footer that stays at the bottom of the page? | A sticky footer can be created by setting its position to “fixed” or using flexbox with the “flex-grow” property to push it to the bottom. |
What is the CSS “box-sizing” property used for? | The “box-sizing” property is used to control how the total width and height of an element are calculated, including or excluding padding and border. |
What is the CSS “position” property used for? | The “position” property is used to specify the positioning method for an element, such as relative, absolute, fixed, or sticky. |
What is the purpose of the CSS “pseudo-class” :nth-child? | The :nth-child pseudo-class is used to select elements based on their position within a parent container, allowing for styling of specific child elements. |
How can you create a responsive layout using CSS Grid? | CSS Grid provides a powerful tool for creating responsive layouts. By using grid templates and media queries, you can adjust the grid’s structure and item placement based on different screen sizes. |
How can you center an element both horizontally and vertically in CSS? | You can center an element both horizontally and vertically by combining techniques such as setting the parent container to “display: flex” and using alignment properties like “justify-content” and “align-items”. |