Technical Questions (CSS) Flashcards

These questions are all about CSS (31 cards)

1
Q

What is CSS selector specificity?

A

CSS selector specificity is a ranking system that determines which CSS rule applies when multiple rules could apply to the same element.

Specificity is calculated based on the types of selectors used: inline styles, IDs, classes, attributes, and element selectors.

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

What is the difference between resetting and normalizing CSS?

A
  • Resetting CSS: removes all default browser styles
  • Normalizing CSS: preserves useful default styles while correcting inconsistencies

Choosing between them depends on the project requirements and desired browser behavior.

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

Describe floats and how they work.

A

Floats are a CSS positioning technique that allows elements to be taken out of the normal document flow and positioned to the left or right of their container.

Floats are commonly used for text wrapping around images.

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

Describe z-index and how stacking context is formed.

A

Z-index is a CSS property that determines the stack order of elements. Higher values are stacked on top of lower values.

A new stacking context is formed when an element is positioned and has a z-index value other than ‘auto’.

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

Describe BFC (Block Formatting Context) and how it works.

A

BFC is a layout mechanism that allows block-level elements to be contained within a specific area, preventing margin collapse and controlling floats.

Elements that create a BFC include floated elements, absolutely positioned elements, and elements with overflow set to anything other than ‘visible’.

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

What are the various clearing techniques and which is appropriate for what context?

A
  • Clearfix: adds a pseudo-element to clear floats
  • Overflow: setting overflow to ‘auto’ or ‘hidden’
  • Clear property: using the clear property on an element

The choice depends on the layout and specific requirements of the design.

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

Explain CSS sprites, and how you would implement them on a page or site.

A

CSS sprites combine multiple images into a single image file to reduce HTTP requests.

To implement, use background positioning to display the desired part of the sprite.

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

How would you approach fixing browser-specific styling issues?

A

Use CSS resets, vendor prefixes, and feature detection tools like Modernizr.

Testing across different browsers and using conditional comments or polyfills can also help.

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

How do you serve your pages for feature-constrained browsers?

A

Use progressive enhancement, graceful degradation, and serve simplified versions of pages.

Techniques include using HTML5 shims and avoiding CSS features unsupported by older browsers.

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

What are the different ways to visually hide content (and make it available only for screen readers)?

A
  • Using display: none;
  • Using visibility: hidden;
  • Using position: absolute; with off-screen positioning

The choice depends on whether the content should be completely hidden or just visually hidden.

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

Have you ever used a grid system, and if so, what do you prefer?

A

Yes, I prefer using CSS Grid for its flexibility and control over layout.

Grid systems help create responsive layouts more efficiently.

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

Have you used or implemented media queries or mobile specific layouts/CSS?

A

Yes, media queries are essential for responsive design, allowing styles to adapt based on screen size.

They enable different layouts for mobile, tablet, and desktop views.

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

Are you familiar with styling SVG?

A

Yes, SVG can be styled with CSS just like HTML elements.

This includes setting fill, stroke, and other properties.

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

Can you give an example of an @media property other than screen?

A

@media print { … }

This targets styles specifically for printed documents.

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

What are some of the ‘gotchas’ for writing efficient CSS?

A
  • Overly specific selectors can lead to maintenance issues
  • Excessive use of !important can cause conflicts
  • Not using shorthand properties can increase file size

Keeping CSS organized and modular helps avoid these issues.

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

What are the advantages/disadvantages of using CSS preprocessors?

A
  • Advantages: variables, nesting, mixins, and functions
  • Disadvantages: added complexity and build process

Preprocessors like SASS and LESS enhance CSS but require a compilation step.

17
Q

Describe what you like and dislike about the CSS preprocessors you have used.

A
  • Like: Improved organization and maintainability
  • Dislike: Learning curve and build setup

Personal preferences may vary based on project needs.

18
Q

How would you implement a web design comp that uses non-standard fonts?

A

Use @font-face to load custom fonts and ensure fallbacks are in place.

This allows for consistent typography across different browsers.

19
Q

Explain how a browser determines what elements match a CSS selector.

A

The browser parses the HTML and CSS, applying specificity rules and inheritance to determine which styles apply.

It checks the DOM tree against the CSS rules in the order they are defined.

20
Q

Describe pseudo-elements and discuss what they are used for.

A

Pseudo-elements are used to style specific parts of an element, such as ::before and ::after.

They allow for additional styling without adding extra HTML elements.

21
Q

Explain your understanding of the box model and how you would tell the browser in CSS to render your layout in different box models.

A

The box model consists of margins, borders, padding, and the content area. Use box-sizing to control how the box model is applied.

box-sizing: border-box; includes padding and border in the element’s total width and height.

22
Q

What does * { box-sizing: border-box; } do? What are its advantages?

A

It changes the box model so that padding and borders are included in the element’s total width and height.

This simplifies layout calculations and prevents overflow issues.

23
Q

What is the CSS display property and can you give a few examples of its use?

A

The display property controls how an element is displayed on the page. Examples include:
* block
* inline
* flex
* grid

Each value affects layout and behavior differently.

24
Q

What’s the difference between inline and inline-block?

A
  • Inline: elements do not start on a new line and only take up as much width as necessary
  • Inline-block: elements do not start on a new line but can have width and height

Inline-block allows for padding and margins to be applied.

25
What's the difference between a **relative**, **fixed**, **absolute**, and **statically positioned** element?
* Relative: positioned relative to its normal position * Fixed: positioned relative to the viewport * Absolute: positioned relative to the nearest positioned ancestor * Static: default positioning, not affected by top, bottom, left, or right ## Footnote Each positioning type affects layout and flow differently.
26
What existing **CSS frameworks** have you used locally, or in production? How would you change/improve them?
I've used Bootstrap and Foundation. Improvements could include customizing components for better performance and reducing bloat. ## Footnote Tailoring frameworks to specific project needs can enhance efficiency.
27
Have you played around with the new **CSS Flexbox** or **Grid specs**?
Yes, both Flexbox and Grid provide powerful layout options for responsive design. ## Footnote They allow for more control over alignment and distribution of space.
28
Can you explain the difference between coding a web site to be **responsive** versus using a **mobile-first strategy**?
* Responsive: adapts to various screen sizes * Mobile-first: designs for mobile devices first, then scales up for larger screens ## Footnote Mobile-first often leads to better performance on smaller devices.
29
How is **responsive design** different from **adaptive design**?
* Responsive design: fluid layouts that adapt to screen size * Adaptive design: fixed layouts that change based on specific breakpoints ## Footnote Responsive design is more flexible, while adaptive design is more rigid.
30
Have you ever worked with **retina graphics**? If so, when and what techniques did you use?
Yes, I used higher resolution images and SVGs to ensure clarity on retina displays. ## Footnote Techniques include using `srcset` for responsive images.
31
Is there any reason you'd want to use **translate()** instead of absolute positioning, or vice-versa? And why?
Using **translate()** can improve performance by avoiding layout recalculations, while absolute positioning is more straightforward for fixed layouts. ## Footnote The choice depends on the specific layout requirements and performance considerations.