Basic CSS Flashcards
(34 cards)
How do developers deal with style difference between browsers?
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.
What is the difference between CSS and HTML?
Whereas HTML is about structure and content (aka, the “content layer”), CSS is about style and appearance (“presentation layer”).
What is CSS?
What is its syntax?
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.
What is a ruleset?
Describes how input elements should look.
It consists of a selector, which is the elements that will be targeted by the declarations that follow.
What is a declaration block?
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.
What is a declaration?
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 do you write comments in CSS?
/* this is a comment */
T/F: When writing a ruleset, you want to keep your selectors as specific as possible.
Why?
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.
What is a pseudoclass?
A pseudo-class is used to target a special state of the element/document.
i.e. div.foo:hover
What is a pseudo-element?
A pseudo-element is used to style specified parts of the element/document.
i. e. p::first-letter
* *Note the double colon*
How do you link an external styelesheet in an HTML page?
In the head:
<link rel=”stylesheet” type=”text/css” href=”./css/main.css”>
What are engineers referring to with the saying “maintaining the separation of concerns” between HTML and CSS?
It’s best practice to AVOID inline styling and use HTML only for describing structure and content and to use CSS to describe presentation.
Why should you avoid using inline styles?
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.
What is the benefit of isolating presentation into our CSS?
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).
What would be a reason for using a style element?
Improving page load speed.
What is the rule of specificity?
Style rules with higher specificity will trump those with lower specificity if there are conflicting values being set for some property.
What is the cascade?
The cascade is a process browsers follow to determine which CSS values get applied for all the properties on a given element.
The Cascade: To determine which property-value pairs to apply to a particular element, what does the browser do?
- 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.
What does the keyword !important allow you to do?
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).
Describe the box model:
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

Given the box model, how do you calculate the measurements for an element?
Add width, plus 2x padding, plus 2x border, plus 2x margin.
What does the box-sizing property do?
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; }
What are webfonts?
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.
Name 8 common selector types. Give examples.
- 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”] {…})