CSS Basics Flashcards

(15 cards)

1
Q

What does CSS stand for and what is its primary purpose?

A

CSS stands for Cascading Style Sheet. It is used to style webpages and set how the page will look. CSS uses HTML markup to apply specific styles to different elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Write the basic syntax structure for CSS styling.

A

selector { property: value; property: value; } - Selector targets the element - Properties and values are inside curly braces - Each property-value pair ends with semicolon

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the three main types of CSS selectors and give an example of each?

A
  1. Element selector: body { background-color: lightblue; } 2. Class selector: .highlight { background-color: yellow; } 3. ID selector: #special { color: red; font-size: 20px; }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you target an HTML element by its class name in CSS?

A

Use a dot (.) before the class name. Example: .highlight { background-color: yellow; font-weight: bold; } - This targets all elements with class=’highlight’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you target an HTML element by its ID in CSS?

A

Use a hash (#) before the ID name. Example: #special { color: red; font-size: 20px; } - This targets the element with id=’special’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are pseudo-classes and what is their syntax structure?

A

Pseudo-classes are added after selectors to change styling only in specific situations. Syntax: selector:pseudo-class { property: value; } - They represent events happening on or to the element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Write CSS code that changes a button’s background to dark blue when the mouse hovers over it.

A

“.my-button:hover { background-color: darkblue; } - :hover pseudo-class triggers when mouse is over the element - Applies only to elements with class ‘my-button’”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Write CSS code that makes a button shrink slightly and turn navy when clicked.

A

“.my-button:active { background-color: navy; transform: scale(0.95); } - :active pseudo-class triggers when element is clicked - transform: scale(0.95) shrinks to 95% size”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What’s the difference between :hover and :active pseudo-classes?

A

:hover triggers when mouse is hovering over element (mouse over). :active triggers when element is being clicked/pressed (mouse down). :hover is for mouse presence, :active is for interaction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Fix this CSS code: body background-color: lightblue

A

body { background-color: lightblue; } - Missing opening curly brace after selector - Missing closing curly brace after property - Missing semicolon after property value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

You want to style all paragraph elements to have red text. Write the CSS.

A

p { color: red; } - Use element selector ‘p’ to target all paragraph elements - ‘color’ property controls text color

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What’s wrong with this CSS? .my-class { color red; font-size: 16px }

A

Missing colon after ‘color’ property and missing semicolon after ‘red’ value. Should be: .my-class { color: red; font-size: 16px; } - Also missing final semicolon is bad practice.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How would you make a class called ‘warning’ have yellow background and bold text?

A

“.warning { background-color: yellow; font-weight: bold; } - Use class selector with dot - background-color for background - font-weight: bold for bold text”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Write CSS that makes an element with ID ‘header’ have a font size of 24px and blue color.

A

header { font-size: 24px; color: blue; } - Use ID selector with hash - font-size property for text size - color property for text color

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What happens when you use CSS without HTML markup?

A

CSS cannot work without HTML markup because CSS uses HTML elements, classes, and IDs as targets for styling. CSS needs the HTML structure to know which elements to style.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly