CSS - Core Concepts Flashcards
True or False, percentage values are calculated relative to their parent element
True, percentage values are calculated relative to their parent element, e.g. a div with a width of 80% would use 80% of its parent element
which css will be applied in the following?
- link href=”style1.css” rel=”stylesheet”
- style
.btn-lg { size : 20px;} /style
- link href=”style2.css” rel=”stylesheet”
- link href=”style2.css” rel=”stylesheet” will be applied since it is the last css that is loaded, hence its called css - cascading style sheet
what is specificity
specificity is the means by which the browser determines which css property values are most relevant and therefore applicable to an element
what is a css reset?
a css reset is a collection of styles that nullify the default browser styles
what does a selector do?
A selector tells css which element to style, eg p {font-size: 15px}
a css declaration contains _ and _
a css declaration contains a property and a value div + p { font-size : 16px } - font-size is the property and 16px is the value
what are absolute values, give examples
Absolute values are fixed values, well suited for devices with a known output size. Examples are inches, cm, mm, pt and picas
what are relative values(units)
relative values are values whose value is relative to the length of another property. They are well suited for devices like screens, where the device size and resolution is not known or could change. examples are em, ex, px, gd - grids, rem - root ems, etc
why are pixels relative values
pixels are relative because they are relative to the size of the device they are displayed, for example, if you change the resolution, the pixel will change its size as well
explain em
em means the value of text at its default size, if for example, 1em is a font size, and the parent of the element which is 1em is 16px, then 1em is 16px. If the child element is 2em, then its actual value is 32px
What are some disadvantages of inline styles
- cumbersome html, tough to read
- does not provide consistency
- difficult to maintain
- inline styles take precedence over page-level style declarations and external stylesheets..this may result in accidental overriding of some styles
- you cannot style pseudo-elements and classes within inline styles
What are some of the disadvantages of embedded or internal style sheets
- this method cant be used for multiple web pages
- page load is slower
- large file size
What are advantages of using external style sheets?
- full control of page structure
- reduced file size
- less load time
Why is it generally discouraged to import stylesheets using @import?
with import, the css files are loaded slower, one by one, whereas with link, the files are loaded in parallel, and therefore faster
Give an example of a group selector
h1, h2, p {
font-family: helvetica;
}
What is a hack?
A hack is browser-specific code designed to cirmuvent an error
What are some disadvantages with using hacks?
- fixing a problem in one browser can occassionally lead to an error in another
- hacks add weight to your code and makes it harder to maintain
- hacks often break in future browsers
Describe a strategy to deal with browser inconsistencies
- try to avoid conditions that trigger the browser error. This requires familiarity with rendering errors and what triggers them
- place all IE-specific code fixes in a seperate stylesheet and serve them through conditional comments
- design according to existing web standards, ensuring that the design will work across the largest possible browser and device base
- add flexibility in designs, resulting in minor differences going unnoticed
What does display : block do ?
display : block displays the affected elemented as a block element
What is the difference between class and Id?
Class and ID are both html attributes that are utilized by css as selectors. The difference between them is:
- ID - can only be used once in an html document, duplicating an ID name can cause your page to fail validation
- Class - can be used multiple times in an html document, and you can have more than one class name for a single html element
If there is a styling conflict between id and class, which selector would css use? In other words, if an element has both class and id defined, which would be applied?
If there is a styling conflict between id and class, css would apply the id selector’s style because id is more specific, in terms of specificity
Describe a strategy to use when adding classes and ids on an html page
Only add classes and ids on a page when they help extend meaning, not merely for styling purposes
Give an example of an element specific selector
An example of an element specific selector is h2.artist {} , which would target all h2 elements with a specified class of artist
Describe the advantages and disadvantages of specific element selectors
Specific element selector, example, h2.artist {}
Advantage
- Allow you to target specific elements
Disadvantage
- Require more processing work from the browser. Thats why it is important to use only when necessary
What is the universal selector?
A universal selector is a selector that affects every element on the page, example is * { color : red} , every element on the page will be red
What is the difference between a universal selector and inheritance
The difference between a universal selector and inheritance is
- With inheritance, child elements can override the parent style
- With a universal selector, child elements cannot override the parent style
What is the disadvantage of using the universal selector in css reset?
The disadvantage of using the universal selector is css reset is that since the universal selector affects all elements on the page, and the child elements cannot override, you will have to make sure that you explicitly change the individual elements, for example * { padding: 0} , all elements will have a padding of 0, and you will have to remember to change the padding of the elements you do not want to have a padding of 0
Give an example of a descendant selector
An example of a descendant selector is header h1 { color: blue}, which targets an h1 element inside a header element
How can you make a descendant selector efficient?
You can make a descendant selector efficient by reducing the number of specified selectors, e.g. instead of article aside p {}, you could just have aside p. This reduces the overhead the browser requires to process the css