Basic CSS Flashcards

1
Q

What is the structure of CSS Syntax?

A

p {
font-size: 20px,
color: red;
}

p is the selector, which points to the elements that we want to style.

in block we can find declarations which air pairs of properties and values ended by a semicolon

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

What are basic types of selectors that are used commonly?

A

1) p.box {
padding: 10%;
}
looks for <p> elements with class “box”
2) * {color: red}
universal selector, changes everything between tag
3) #one {font-size: 20em;}
id selector
4) grouping selectors with ‘,’</p>

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

What are four different combinators in CSS?

A
1) descendant selector (space)
div p {
      padding: 10%
}
which looks for p in div.
2) child selector (>)
section >h1 {}
h1 that is a child of section
3) adjacent sibling selector (+) h1 + p {}
4) general sibling selector (~) 
h1 ~ p{}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you reset styles?

A
  • {
    margin:0;
    padding:0;
    }
    html { font-size: 10px; }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are possible units to pick in HTML?

A

px - pixels
em - relative unit. Inherits the unit in parent, and multiplies it by the value
rem - inherits from the main page element

em & rem only applies to font-sizes

% - percentages sometimes inherit similarly to em unit. However not always - for example, when we set line-height of the line, it is inherited from the font-size
vh, vw - relative to viewport

There is one nuisance worth mentioning: when we set width to 100vw, there will appear a browser bar, because 100vw does not take into account right browser bar - so set width to 100% not 100vw.

On the other hand setting height to 100% will have no effect, since it is depending on the amount of content - 100vh will work on the element.

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

What is the good practice when setting font size units in document?

A

Because of the fact that the page is going to be rescaled on different resolutions and devices, it is good practice, to have every font relative to the html element with rem unit.
When page is going to be rescaled, we only change the initial html { font-size: } and everything else will change accordingly

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

Popular / basic properties and values in CSS

A

font-size,
background-color,
color (color of the font),
margin: (10px 20 px 20 px 5 px) /* clockwise */ auto - centers the element horizontally (not inherited)
margin-top: (if we want to specify just one direction
padding
border

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

Basic font properties and values.

A

font-family (specifies the family for specific segment)
color (inherited also applies to different tags, sa. borders)
font-size
font-style (normal, italic)
font-weight (bold, normal, 400, 700 - when it comes to non-system fonts)
letter-spacing (especially when we create buttons)
text-decoration (underline, line-through)
text-align (left (default), center, justify)
text-transform (uppercase, captalize, lowercase)
line-height

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

Inherited vs not inherited properties.

A

Inherited:

  • text-transform
  • font-size
  • color
  • font-weight

Not inherited:

  • background-color
  • margin
  • border
  • padding
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to calculate selector’s specifity?

A

1) count 1 if the declaration is from is a ‘style’ attribute rather than a rule with a selector, 0 otherwise (= a) (In HTML, values of an element’s “style” attribute are style sheet rules. These rules have no selectors, so a=1, b=0, c=0, and d=0.)
2) count the number of ID attributes in the selector (= b)
3) count the number of other attributes and pseudo-classes in the selector (= c)
4) count the number of element names and pseudo-elements in the selector (= d)

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

Common block elements vs inline elements

A

Block elements:

<h1>, </h1>

<p>, </p>

<div>, <ul>, </ul><ol>, <li>, , , ,

Inline elements:
<span>, <a>, <em>, <code> and , </code></em></a></span></li></ol></div>

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

What is the difference between vertical margin and horizontal margin of elements when it comes to Box Model?

A

The horizontal margin between two elements is a sum of both margins.
While vertical margin takes the bigger margin.

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

What is the purpose of box-sizing:

A

box-sizing is a functionality that allows us to change how the box is calculated in the box model. (width and height)

Default calculations takes into account content box, padding + border, which is not very convenient

box-sizing: content-box;
box-sizing: border-box;

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

How do you change the direction of the inline elements?

A

For example by changing to display: inline-block

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

How do you apply time to transform the element when changed with pseudoclass

A

with transition: 0.3s

attribute

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

What is the purpose of float?

A

Float is an attribute for floating elements.

You can use it to create a page layout
Menu
To flow text around graphics.

It has many problems, so preferred options are flexboxes and css grids.
overflow: hidden helps with these issues

17
Q

What are pseudo-classes?

A

A CSS pseudo-class is a keyword added to a selector that specifies a special state of the selected element(s). For example, :hover can be used to change a button’s color when the user’s pointer hovers over it.

Common pseudoclasses:
\:hover
\:first-child
\:nth-child(2n)
\:nth-of-type(1)
\:nth-last
18
Q

What are pseudo-elements?

A

CSS pseudo-element is a keyword added to a selector that lets you style a specific part of the selected element(s). For example, ::first-line can be used to change the font of the first line of a paragraph.

\::after
\::before
\::first-letter
\::first-line
\::selection
19
Q

position: fixed

How does it work?

A

The position CSS property sets how an element is positioned in a document. The top, right, bottom, and left properties determine the final location of positioned elements.

1) Position fixed discards an element from the document layout.
2) We attach the element to the browser window. Meaning, scrolling down, will make this element travel along.

z-index:
can help us define which box appears at the top. (works like a layer).

20
Q

Differences between position: fixed and position: absolute

A

1) With position: absolute, the element isn’t glued to the window, and stays in the same place.
2) We do not position it only in relation to the browser window, but also in relation to other elements

First solution for 2):
add position: relative; to its parent (position: absolute, only looks in its ancestors).

21
Q

How is opacity different from rgba when it comes to background blending

A

background-color: rgba (0, 0, 0, 0.5) will darken an element (1, would make it black), but it will have no effect on the content of the element

opacity has effect on both background and content of the element, border etc.

22
Q

What are basic background properties to manipulate background image?

A

background-image: url(‘dance.jpg)’, url(“img/kwiatek.jpg”)
background-repeat: no-repeat;
background-position: 0% 30%;

background-size: cover; ( the image will retain its original size, will cover the whole space, maintain it’s aspect ratio. But will clip some parts of the image)
contain (will not clip image, will retain is original size and aspect ratio, but will not cover whole space).

background-origin: (content-box, border-box, padding-box) (indicates place where the img is going to be drawn)
background-clip: (indicates place where background will be drawn)

23
Q

What does background-attachment property do?

A

The background-attachment CSS property sets whether a background image’s position is fixed within the viewport, or scrolls with its containing block.

24
Q

What is the syntax for applying media queries?

A

Media queries are useful when you want to modify your site or app depending on a device’s general type (such as print vs. screen) or specific characteristics and parameters (such as screen resolution or browser viewport width).

@ (min-width: 460px) {

}

A media query is composed of an optional media type and any number of media feature expressions. Multiple queries can be combined in various ways by using logical operators. Media queries are case-insensitive.

25
Q

What does mobile first concept mean?

A

It starts development of webpages from mobile to desktop.
A very important aspect is that the media queries need to be done from desktop first to smallest max-width. Or mobile first. Mixing different breakpoints, will destroy the structure.

26
Q

What are most common media queries?

A

min-width,
max-width, depending if we choose mobile first or desktop first approach
orientation: portrait,
orientation: landscape.

27
Q

What are initial values?

A

The initial value of a CSS property is its default value, as listed in its definition table. The usage of the initial value depends on whether a property is inherited or not:

For inherited properties, the initial value is used on the root element only, as long as no specified value is supplied.
For non-inherited properties, the initial value is used on all elements, as long as no specified value is supplied.

28
Q

What is word-wrap property?

A

The word-wrap property allows long words to be able to be broken and wrap onto the next line.

word-wrap: normal|break-word|initial|inherit;

29
Q

What are the characteristics of calc() function?

A

The calc() function takes a single expression as its parameter, with the expression’s result used as the value.

width: calc(100% - 80px);

30
Q

What are CSS variables and what is the syntax?

A

Variables in CSS should be declared within a CSS selector that defines its scope. The variable name must begin with two dashes (–) and is case sensitive!

html {
–main-bg-color: coral;
}

You can refer then to those variables with var() function

31
Q

What are CSS variables used for?

A

1) For dynamically changed pages, after an event - changing one element has influence on others just with one variable
2) We do not double code.
3) We write quicker.

Especially useful when we use it in conjunction with javascript

32
Q

When and how should CSS filter: be used?

A

It’s alright to use filters for dynamic images, that change after some BOM event.
If the image is static - it’s much better to prepare it in a graphics program. Because they are heavy for the browser.

filter: blur(3px) - in pixels
filter: brightness (30% or 0.3)
filter: contrast (150% or 1.5)
filter: grayscale (100% - full gray)
filter: opacity (from 0 to 100% - but it also affects text and borders)
filter: sepia (0 to 100%)
filter: saturate (1.6 or 160%, 0 - same effect as grayscale)

33
Q

What are the transition properties that are shortened with transition:
keyword?

A

By default: transition: all 0s ease 0

transition-property: (font-size | background-color | border-color etc.)

transition-duration: (500ms | 0.4s)

transition-timing-function:
ease - start slowly, speed up, at the end slow down
linear - the same speed
ease-in - start slowly and accelerate
ease-out - start quickly and slow down
cubic-bezier(a,b,c,d) - we can define the timing function

transition-delay: 0.2s

34
Q

Which properties are good to be animated with transition property?

A

colors: background-color, color, opacity
sizes: width, height
position: top, bottom, left, right
box-model elements: padding, border, margin
transformations: rotate, scale, translate
other: text-shadow, box-shadow

35
Q

What are the properties of transform?

A

The transform CSS property lets you rotate, scale, skew, or translate an element.

transform: rotate(360deg, 0.5 tiurn)
transform: scale(x,y) (you can create mirror reflection if you pass -1 value)
transform: translate(x, y), translateY()
transform: skew(x, y) (in deg)

transform-origin: (default: 50% 50%)

If the property has a value different than none, a stacking context will be created. In that case, the element will act as a containing block for any position: fixed; or position: absolute; elements that it contains.

36
Q

How do you center an element using transform property?

A

You can use translate function.

position: absolute;
top: 50%;
left: 50%;

transform: translate(-50%,-50%)

37
Q

How can you make jumping to elements via href elements inside of page smoother?

A

By using scroll-behavior: smooth;
property.
It does not require any javascript, but is not supported by all browsers: mainly safari and opera mini.

38
Q

What is a pseudoclass that allows to set up a style of the input if the input is invalid?

A
.form\_\_input:focus {
  outline: none;
  border-bottom: 3px solid #55c57a;
}
.form\_\_input:focus:invalid {
  border-bottom: 3px solid #ff7730;
}

we need also, then type=”email” minlength=8 required or some other attributes that allow to verify the input element.