Basic CSS Flashcards

1
Q

How do developers deal with style difference between browsers?

A

They often use what is called a CSS reset ( most popular of which is the Meyer reset) to zero out default styles and ensure a consistent user experience across browsers.

Another option is normalize.css, which is a CSS library that normalizes a subset of browser elements to be consistent between browsers.

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

What is the difference between CSS and HTML?

A

Whereas HTML is about structure and content (aka, the β€œcontent layer”), CSS is about style and appearance (β€œpresentation layer”).

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

What is CSS?

What is its syntax?

A

CSS (Cascading Style Sheets) is the language used to control the presentation layer. We use it to control the visual aspects of the content on a page: from fonts to color to size to animations and more.

Syntax: Target a set of elements with a CSS selector, and set properties and values as required by your presentational goal.

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

What is a ruleset?

A

Describes how input elements should look.

It consists of a selector, which is the elements that will be targeted by the declarations that follow.

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

What is a declaration block?

A

Follows the selector in a ruleset. It is a set of declarations contained in curly brackets ( {…} ). Within the block, each line is a separate declaration.

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

What is a declaration?

A

A declaration consists of a property and the value it is to be set to. The property name is followed by a colon, and the value is followed by a semicolon.

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

How do you write comments in CSS?

A

/* this is a comment */

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

T/F: When writing a ruleset, you want to keep your selectors as specific as possible.

Why?

A

FALSE.

Keeping selectors as non-specific as possible means that the settings can be reused on other targets if we decide they should have the same rules.

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

What is a pseudoclass?

A

A pseudo-class is used to target a special state of the element/document.

i.e. div.foo:hover

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

What is a pseudo-element?

A

A pseudo-element is used to style specified parts of the element/document.

i. e. p::first-letter
* *Note the double colon*

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

How do you link an external styelesheet in an HTML page?

A

In the head:

<link rel=”stylesheet” type=”text/css” href=”./css/main.css”>

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

What are engineers referring to with the saying β€œmaintaining the separation of concerns” between HTML and CSS?

A

It’s best practice to AVOID inline styling and use HTML only for describing structure and content and to use CSS to describe presentation.

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

Why should you avoid using inline styles?

A

Inline styles encode information about how an element should look directly into the HTML. This means you cannot reuse these styles on other elements. One of the advantages of CSS is reusable classes and classes are not possible with inline styles.

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

What is the benefit of isolating presentation into our CSS?

A

By isolating presentation into our CSS, our code will be more maintainable and extensible (that is, easier to apply presentation rules we’ve set up in one place to new use cases).

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

What would be a reason for using a style element?

A

Improving page load speed.

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

What is the rule of specificity?

A

Style rules with higher specificity will trump those with lower specificity if there are conflicting values being set for some property.

17
Q

What is the cascade?

A

The cascade is a process browsers follow to determine which CSS values get applied for all the properties on a given element.

18
Q

The Cascade: To determine which property-value pairs to apply to a particular element, what does the browser do?

A
  • Determines which rules apply to the element.
  • Takes all the relevant rulesets and sorts them according to their origin (for instance, inline styles vs. external stylesheets β€” inline styles win over external) and importance (more on importance in a moment).
  • Takes all rulesets that have same origin and importance and sorts them by selector specificity
    .
  • If there are still conflicting values for rulesets with the same importance, origin, and specificity, applies the ruleset that was declared last.
19
Q

What does the keyword !important allow you to do?

A

CSS allows you to supply the keyword !importantin order to make a rule that might otherwise be lower in the cascade override others.

Try to avoid using it in your CSS.

There are rare occasions where it’s the right move, but usually, if you have to use !important, it’s a sign that there are problems with the application of your style rules (for instance, you may just need to use a more specific selector).

20
Q

Describe the box model:

A

The basic idea is that most elements on a web page are really rectangular boxes, even if they appear to be a different shape.

The total space taken up by an element is determined by its width, height, padding, border, and margin, as illustrated below:

Mother Bakes Perfect Cookies

Margin, Border, Padding, Content

21
Q

Given the box model, how do you calculate the measurements for an element?

A

Add width, plus 2x padding, plus 2x border, plus 2x margin.

22
Q

What does the box-sizing property do?

A

To have the box model respect the widths we explicitly set, we can use the box-sizing CSS property.

We set its value to border-box.

By putting the following ruleset in your CSS, you can make border-boxthe default for all elements:

* { box-sizing: border-box; }

23
Q

What are webfonts?

A

To use any font beyond web safe fonts, you have to use webfonts. Webfonts are fonts that you load in the browser using HTML and then can reference in your CSS.

24
Q

Name 8 common selector types. Give examples.

A
  • Element selectors (e.g., p {…})
  • Combination selectors (e.g., .foo.bar {…})
  • Multi selectors (e.g., .foo, .bar {…})
  • Descendant selectors (e.g., .foo li {…})
  • Direct child selectors (e.g., .foo > li {…})
  • Before and after pseudo-elements selectors (e.g., li::before {…})
  • Anchor pseudo-classes (e.g., a:hover {…})
  • Attribute selectors (e.g., input[type=”text”] {…})
25
Q

What are element selectors?

A

The element selector just consists of the element you want to target.

26
Q

What are combination selectors?

A

Sometimes to implement a design, you’ll need to target elements that have two or more classes, for instance.

The rule is: if an element is part of the target, put it first. Then, chain together the classes you want to target.

i.e. p.foo.bar { /* make some rules */ }

27
Q

Describe multiple selectors.

A

To target multiple selectors with the same ruleset, just separate your selectors with commas.

i.e. .foo, .bar, .bizz.bang { /* make the rules */ }

28
Q

What are descendant selectors?

A

Descendant selectors target children of the parent element whether they’re immediate children or further down the hierarchy.

i.e. aside p { /* make rules */ }

29
Q

What are child selectors?

A

Sometimes we need to target only elements that are direct children of an element. For that we can use the direct child selector:

i.e. aside > p { /* make rules */ }

30
Q

What do the ::before and ::after pseudo-elements allow you to do?

A

The ::before and ::after pseudo-elements allow you to render content just before or after your element.

Writing ::before and ::after style rules can be a good way to handle repeated visual content that surrounds an element.

31
Q

What are the five important anchor pseudo-classes?

A

a:link { /* unvisited link */ }

a:visited { /* visited link */ }

a:hover { /* mouse over link */ }

a:focus { /* keyboard focus on link */ }

a:active { /* selected link (i.e., you’ve clicked but not released on the link) */ }

32
Q

What are attribute selectors?

A

CSS lets us target elements by attribute value. A common use for this is targeting specific kinds of form inputs (for instance, input[type=”radio”] to apply rules exclusively to radio selector inputs).

33
Q

Attribute selectors: describe the options for matching attribute values.

A
  • Exact match: element[attribute=value]
  • Match pattern anywhere in value: element[attribute*=value]
  • Match pattern at beginning of value: element[attribute^=value]
  • Match pattern at end of value: element[attribute$=value]
34
Q

What is the difference between ID & class selectors?

A

In the CSS, a class selector is a name preceded by a full stop (β€œ.”) and an ID selector is a name preceded by a hash character (β€œ#”).

The difference between an ID and a class is that an ID can be used to identify one element, whereas a class can be used to identify more than one.

ID selectors have very high specificity.