CSS Flashcards
What are the ‘methods’ for writing CSS called? / what is the word for any coding language’s ‘language’?
syntaxes
Give two types of syntaxes for CSS / two ways of writing and applying CSS
ruleset in CSS
and
inline style (used in HTML)
What do all CSS syntaxes use?
declarations
What do declarations do in CSS
apply style to the selected element
What is the extension for CSS files?
.css
How do you write CSS within an HTML file?
by enclosing the code in a style tag < style >
Define this Ruleset(.css) syntax term: selector
selector {
}
the beginning of the ruleset used to target the element that will be styled
Define this Ruleset syntax term: declaration block
the code in-between (and including) the curly braces { } that contains the CSS declaration(s).
Define this ruleset (.css) syntax term: declaration
the group name for a property and value pair that applies a style to the selected element
Define this Ruleset syntax term: property
The first part of the declaration that signifies what visual characteristic of the element is to be modified
Define this Ruleset syntax term: value
the second part of the declaration that signifies the value of the property
Define this Ruleset inline style term: opening tag
the start of an HTML element. This is the element that will be styled
Define this Ruleset inline style term: attribute
the style attribute is used to add CSS inline styles to an HTML element
Define this Ruleset inline style term: declaration
the group name for a property and value pair that applies a style to the selected element
Define this Ruleset inline style term: property
the first part of the declaration that signifies what visual characteristic of the element is to be modified
Define this Ruleset inline style term: value
the second part of the declaration that signifies the value of the property
How do you close off inline style attributes?
With a semicolon ;
Are inline styles the best way to style HTML?
no
What is the CSS code written/nested within the < style > element of HTML called?
internal stylesheet
Where must an internal stylesheet be placed?
Within the < head > element
Why is an external stylesheet useful?
because you don’t have to sacrifice the readability and maintainability of your HTML code
When using an external style sheet (.css file) what must you do?
Link the .css file to the .html file
How do you like a .css file to a .html file?
with the < link > element, which must be placed within the < head >
What two attributes does a < link > linking a .css file to a .html file need?
an href=”” which links to the .css file
a real attribute, which describes the relationship between the HTML file and the CSS file
What should the red attribute be set to when linking a .css file to an .html file?
rel = ‘stylesheet’
< link href=”insert link to .css file here” rel=’stylesheet’ >
What is the symbol for universal selector in CSS?
the asterisk *
How do you select an HTML element by its class?
a period ( . ) must be prepended to the class’s name ie .brand (with brand being class=’brand’ in HTML
How do you style a single element uniquely?
using the id=”” attribute in HTML
How many values does the class=’’ attribute accept?
Many
How many values does the id=”” attribute accept?
only one, and can be used only once per page
how do you select an element’s id in CSS?
prepend id with # #id, #large-title
how can the attribute selector be used?
to target HTML elements that already contain attributes, and elements of the same type can be targeted differently by their attribute or attribute value
how do you select attributes in CSS?
with [ ] around the attribute
ie. [href] {
}
What are pseudo-class selectors?
selectors that change the appearance of elements after user interaction
give examples of pseudo-class selectors
:focus :visited :disabled :active
how is a pseudo-class attached to a selector
with a colon
ie: p:hover {
}
what is specificity?
the order in which the browser decides which CSS styles will be displayed
What is best practice with specificity?
to style elements with the lowest degree of specificity so that if an element needs a new style, it is easy to override
what is the most specific selector in CSS
the id selector
how do you select a class
. with a period
how can you make styles easier to edit?
style with a type selector
what is it called when we combine multiple selectors?
chaining
What does the font-weight property control in CSS?
how bold or thin the text appears
What properties can you use with text-align?
justify, left, right, center
what does foreground color apply to?
the element being styled with color - ie giving a header a color is giving it a foreground color
what does the css syntax for giving an element a background image look like?
.main-banner {
background - image: url( ‘https: insert link here ‘ );
}
what does the relative path for an image look like?
for image with file name mountains.jpg:
url(‘images/mountains.jpg’);
What can you use to override any style in css?
! important ;
how do you affect the transparency of an element?
with the opacity: property
What values can you give to the opacity property?
a number in the range 0.0 to 1.0
or
a percentage from 0% to 100%
h2 { opacity: 0.50; or opacity: 50% }
what is meant by the box model?
elements on the page being interpreted as “living” inside a box
What does the box model include?
a page’s content’s area size (width and height), and its padding, border, and margin
width, height, padding, border, mardin
how many dimensions does an element’s content have?
two: height and width
What are the dimensions of an HTML box set to by default?
by default it holds the raw contents of the box
what happens when an element’s dimensions are set in pixels (px)
the element will be the same size on all devices - something that fits a laptop screen will overflow a phone or tablet screen
What can you set to change a border?
width, style, and colour
how do you changer a border’s width?
in pixels, or with keywords: thin, medium, or thick
How many styles can web browsers render for borders?
10 - including: none; dotted; solid
What is the default border?
medium none color
how do you modify the corners of an element’s border box
with the border-radius property
how do you create a border that is a perfect circle?
by creating an element with the same width and height, then setting the radius to half the width of the box, which is 50%
border-radius: 50%;
when would border-radius: 100%; not give a perfect circle border?
when the height and width are not the same, ie you need a square element to create a circle border
What is the space between the contents of a box and the borders of a box called?
the padding
what is padding
the space between the borders of a box and the contents of a box
padding is like the space between a picture and the frame
how can you be more specific about padding?
with more specific padding properties: padding-right padding-left padding-top padding-bottom
What do you call a declaration that uses multiple properties as values?
shorthand property
how does padding shorthand work
in clockwise rotation
how do you use padding shorthand if the left and right padding are equal?
with 3 values, the first is padding-top, second value is padding left and right, and the last is padding-bottom
how do you use padding shorthand if padding top and bottom are equal, and padding left and right are equal?
with two values, the first sets padding top and bottom, and the second sets padding right and left
What does margin refer to?
the space directly outside of the box
How can you use margin to centre content?
with the instructions: margin: 0 auto;
how does margin: 0 auto; work?
the 0 sets the top and bottom margins to 0 pixels, and the auto instructs the browser to adjust left and right margins until the element is centred within the containing element
What needs to be set for an element to be centred?
the width
when is it not possible to centre an element?
when it takes up the full width of the page
padding is space added ____ an element’s border
inside
margin is space added ___ an element’s border
outside
what is the difference between vertical margins and horizontal margins?
vertical margins collapse, whereas horizontal margins do not collapse
how far apart would two side-by-side elements be?
as far apart as the sum of their adjacent margins
vertical margins do NOT do this
do horizontal margins collapse?
no
do vertical margins collapse?
yes
What can you do to prevent elements changing size too much on different devices?
with the min-width and max-width properties, as well as min and max height
what happens if an element’s max-height is set too low?
the content might spill out of the box, making the content illegible
how are the total dimensions of an element calculated?
by adding all of the vertical dimensions and all of horizontal dimensions together
how do you control overflow?
with the overflow property
what are some values you can use with the overflow property?
hidden (any content that overflows is hidden) scroll (any content that overflows can be made visible with a scrollbar) visible (overflow content is displayed outside of the containing element - this is the default value)
What is the default overflow value?
visible
Where is the overflow property set?
On a parent element, so that the browser is instructed properly on how to render child elements too
What is a browser’s default stylesheet called?
user agent stylesheet
user agent in this case is a technical term for the browser
When properties are set to 0, do they need a unit of measurement?
no
How do developers start with a clean slate for their CSS coding?
with: * { margin: 0; padding: 0; }
how do you hide elements?
with the visibility propety
what can you use to set the visibility property?
hidden (hides an element - but still leaves space where the element was intended to be), visible (displays an element), collapse (collapses an element)
What’s the difference between display: none and visibility: hidden?
display: none will completely remove an element from a page
visibility: hidden will not be visible but the space reserved for the element will be visible
How do you change the spacing between individual letters in text?
with the letter-spacing property
What is the limitation of the box model?
everything added to the box, such as borders, padding, height and width, etc increases the box ‘size’, making it difficult to accurately size a box
What is the ‘formula’ for the actual rendered width of an element’s box when content-box is the value of the box-sizing property?
width + padding + border = actual rendered width
What property controls the type of box model the browser should be using?
the box-sizing property
What is the default value of the box-sizing property?
content-box
How do you ‘reset’ the box model?
by assigning the value border-box to the box-sizing property:
box-sizing: border-box;
What does the value border-box do the property box-sizing?
box-sizing: border-box;
height and width of the box remain fixed, and border thickness and padding will be included inside of the box - therefore the overall dimensions of the box don’t change
What is the universal selector?
- {
}
All HTML elements are ____?
boxes
All HTML elements are boxes made up of _ components
4
What are the 4 components of HTML elements (box model)
content container, padding, border, margin
What is the order of the box model?
CPBM Content Padding Border Margin
CPBM!
How do you /does the browser calculate the width of the box of an HTML element?
the sum of: content width + padding left and padding right width + border left and border right width = total width of an HTML element’s box
How do you / does the browser calculate the total size of an HTML element’s height?
the sum of: content height + padding top and padding bottom height + border top and border bottom height = total height of an HTML element’s box
Why is margin not included in the calculations to find an HTML element’s box height/width size?
because margin adds space only around the outside of an HTML element’s box, so it doesn’t affect how big or small an HTML element box is (only affects how near or far other HTML elements can come to it)
What is the default position for block-level elements?
on the left side of the browser
How can you change the default position of an element?
by changing its position property
Give 5 values the position property can take as values
static (refers to default behaviour), relative, absolute, fixed, sticky
What needs to go with the declaration ‘position: relative’?
offset properties: top, bottom, right, left, which can be specified in pixels
What happens when you set ‘position’ to absolute?
other elements ignore that element and will act like it’s not present on the page, and scrolls outside of view of the user scrolls away
What happens when you set an element’s ‘position’ to fixed?
it is fixed in place and stays on the page when the user scrolls
What is ‘position: fixed;’ often used for?
Navigation bars or fixed headers at the top of pages
Which position declarations stay in the normal flow of a document?
static, relative, sticky
Which position declarations are removed from the normal flow of a document?
fixed and absolute
What property controls how far back or far forward an element should appear when elements on the page overlap?
the z-index property
can be thought of as the depth element, with deeper elements appearing behind shallower elements
What values does the z-index property accept?
integer values, which instruct the browser on the order elements should be layered on the page
What element property does z-index not work on?
static
give 3 values for the display property
inline, block, inline-block
Which elements have default display of ‘inline’?
< em >, < strong >, < a >
What does the display: inline; property do to elements?
Inline elements have a tight box around them, only taking up the necessary amount of space
and renders inline elements on the same line as other inline elements immediately before or after if there are any
inline elements can share lines with other elements
What can you not declare for elements that are display: inline by default?
height and width
What are elements called that are not displayed in the same line as the content around them?
block-level elements
What is the default width and height of block-level elements?
block-level elements fill the width of a page by default, and their height is the necessary size to accommodate their content
What are some elements that are block-level by default?
all headings ( < h1 > to < h6 > ), < p >, < div >, and < footer >
What is the float property useful for, and commonly used for?
moving an element as far left or as right as possible, and wrapping text around an image
What must float elements have specified?
the width
What property specifies how elements should behave when they bump into each other on a page?
the ‘clear’ property
What values can the clear property take?
left (left side of the element will not touch any other elements within the same containing element)
right (right side of the element will not touch any other elements within the same containing element)
both (neither side of the element will touch any other element within the same containing element)
none (the element can touch either side)
In terms of display, what is the difference between < div > and < span >
Div is a block element, which takes up the whole space of a line
Span is an inline element
What is the difference between inline and inline-block?
inline-block allows you to set width and height
What does the property ‘display’ do?
set an element’s behaviour to inline, inline-block, or block
Do inline-block elements start on a new line?
no
What are the 3 ways color can be described in CSS?
named colors: also known as keyword colors
RBG: numeric values that describe a mix of red green and blue
HSL: numeric values that describe a mix of hue, saturation, and lightness
How do you style foreground, and background color?
color:
background-color:
What is the syntax used for hex colors?
hexadecimal, beginning with #
How many characters are used in hexadecimal syntax?
3 or 6