CSS Assignment – 1
Basic Questions
- Write HTML and CSS to change the background color of a <p> element to lightblue using inline CSS.
- Create an HTML file with an internal CSS block that changes the font color of all headings to green.
- Use an external CSS file to set the body background color to yellow.
- Apply the universal selector (*) to give all elements a margin of 5px.
- Use an element selector to make all <h1> tags red.
- Create a class .highlight that underlines text and apply it to two different <p> tags.
- Define an ID selector #main-title and apply it to a heading to change its font size to 30px.
- Use a grouping selector to apply the same color to <h1>, <h2>, and <h3>.
- Add a CSS comment above a style rule and check if it hides correctly.
- Create a link (<a>) and use the :hover pseudo-class to change text color when the mouse hovers.
- Use the :first-child pseudo-class to make the first <li> in a list bold.
- Add a :last-child pseudo-class style to make the last paragraph italic.
- Use an absolute unit (px) to give a heading a font size of 25px.
- Use a relative unit (em) to set paragraph font size relative to its parent.
- Apply vw unit to make a heading font size scale with the viewport width.
- Create two <div> elements and style the second one differently using the adjacent sibling selector (+).
- Use the child selector (>) to apply a color only to direct <li> children of a <ul>.
- Style all paragraphs that are siblings of an <h1> using the general sibling selector (~).
- Use rem unit for setting global font size and apply it across elements.
- Create three <p> elements and use inheritance by setting font-family on the <body> tag.
Intermediate Questions
- Create a navigation menu and apply different colors when links are in hover, visited, and active states using pseudo-classes.
- Apply different background colors to odd and even rows in a table using :nth-child() pseudo-class.
- Design an internal CSS style sheet that uses both ID and class selectors with different styles.
- Use two selectors combined (section p) to change color of <p> only inside <section>.
- Create a button and use :active pseudo-class to make it shrink slightly when clicked.
- Use grouping selectors to style both <p> and <span> tags with the same font.
- Define an external CSS file and link it using the <link> tag to a given HTML file with multiple sections.
- Style <h2> differently based on whether it is a child of a section or a child of an article.
- Create a simple card UI with fixed width and padding using absolute units (px, cm).
- Use relative units (%) to give an image 50% width of its parent.
- Create two nested containers and apply inheritance so that text inside inherits parent styles but overrides one property.
- Build a small HTML snippet where inline CSS overrides external CSS.
- Design a paragraph that changes color when you highlight text using the ::selection pseudo-element.
- Add a ::first-letter pseudo-element effect to style the first letter of a paragraph larger and bold.
- Use ::first-line pseudo-element to style the opening line of a text differently.
- Show an example where CSS specificity resolves conflict between inline, ID, and class styles.
- Create a webpage where header text uses vh to scale with viewport height.
- Create two divs side by side; apply general sibling selector (~) to style second if first exists.
- Demonstrate difference between em and rem by nesting multiple divs with text sizes.
- Style only <span> that are immediately after <strong> using adjacent sibling selector (+).
Advanced Questions
- Create a responsive webpage layout where headings use vw and vh units to scale with the browser window.
- Design a multi-level navigation menu using descendant selectors and pseudo-classes that highlight parent vs child items differently.
- Show an example of CSS specificity conflict with 3 elements styled using inline, class, and ID selectors, and explain which one wins.
- Build a profile card component where the first child, last child, and general siblings all have different styles.
- Demonstrate inheritance override by styling a parent font-family globally but overriding child font-size using em and rem.
- Create a list of 10 items and use advanced nth-child selectors (nth-child(2n+1), nth-child(3n)) to style differently.
- Apply both pseudo-elements (::before, ::after) to create decorative content around headings without changing HTML.
- Show an example where absolute units (px) break responsiveness but relative units (%, em, rem, vw, vh) fix it.
- Build small demo where using inline CSS, external CSS, and internal CSS together produces unexpected results if order of precedence is not understood.
- Demonstrate how specificity hierarchy works with complex selectors like ul li:first-child a.class#id.