CSS Flashcards

(35 cards)

1
Q

What is CSS selector specificity and how does it work?

A

Specificity is where you have 2 CSS styles that conflict for example 2 that modify 1 element, this uses a priority system to determine which of the 2 conflicting styles in used using weightings for the elements. An example is if you have a class with in line styling but you also have styling in a style sheet for the element, the priority will use the style from the inline since it has higher weight.

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

What’s the difference between “resetting” and “normalizing” CSS? Which would you choose, and why?

A

CSS resetting as the name implies resets all stylings, this means everything will look the same, for example a h1 or heading 1 will look the same as a heading 2 and the idea is that you’d individually style each of these manually. Normalizing is where you make elements appear the same across all browser based on the code you write. For example if you change a font size it’ll be the same font size regardless of the browser. Personally I’d go with normalizing as I feel it’s a waste to reset all the styling only to manually style it again.

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 positioning style which makes the elements appear in line with the content. For example if you use a float left the text will wrap around the image instead to the right. if for example you used position absolute instead the text would overlap the image. Float is essentially a positioning style to add an element into the flow of the website meaning the other parts of the website like the text will be affected by them.

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 the view of the html as a 3 dimensional page, where the z index determines how content is stacked. If you have an image and text in the same position if you assign them both z index values, the one with the higher value will overlap the one with the lower value. z index only applies to elements that are positioned such as position absolute.

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

Block formatting context works with floats and allows you to create boxes around child elements within the box which works with floats. For example if you have a float left and some text, without block formatting context the container for both of them will wrap around the length of the text, but if BFC is applied then it will apply around the float too.

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

the clear property moves the content to be displayed after the floating element depending on the side. For example if you used clear: left it’ll display the content after the left float, this can also be applied to right too or both. There is also a “clearfix” which can be applied to floats which will clear the element so that the container is automatically resized to the size of the float so the content will be displayed below.

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

How would you approach fixing browser-specific styling issues?

A

one option is to use a CSS framework which automatically handles the browser specific styling such as bootstrap. you can also use reset or normalize CSS depending on which you prefer which will clear the CSS so that you can individually style each element or use a set of consistent styling between browsers.

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

One option is to use a CSS framework which automatically handles the browser specific styling such as bootstrap. you can also use reset or normalize CSS depending on which you prefer which will clear the CSS so that you can individually style each element or use a set of consistent styling between browsers.

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

There are websites that allow you to see what features each browser is compatible with. This can be used to make sure the website meets the target browser specifications. When designing the website it’s possible to have the basic features compatible with all browser types and then add specific features for browsers that support them.

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

Set the visibility to hidden for the element, make the size 0, or use position element with a large value to remove it from screen view. For example, use position absolute then set the position to a really large number to the left or right.

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

In some of my early projects I used the float system, but later on I started using bootstrap more often which uses flex and flexbox which is widely compatible and works well for the times iv needed to use it.

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 on my project during university I had to change the navigation bar for mobiles, so I changed it so that you would click a button and the navigation bar would appear from the left side instead with the navigation links stacked. This only occurred on devices which a screen size below a certain range.

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

Are you familiar with styling SVG?

A

SVG are vectors that can be used to create shapes on the website. Just like other elements on the website you can style them to change the colours and other properties. I haven’t used them in my projects but I’ve experimented with using them but never stuck with it.

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

print. Media lets you style based on the device the user is using for example if they have a smaller screen you can change the design to be more suitable.

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

Keep the CSS to the top of the page if not in a style sheet is one. Also when styling elements that are child elements, don’t add redundant elements. For example don’t add selectors such as body as it’s not really needed.

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 pre-processors?
Describe what you like and dislike about the CSS pre-processors you have used.

A

One of the main advantages that I’ve used pre-processors for is the ability to create variables similar to php which can be applied to certain parts of the style sheet. For example if you have a colour that’s going to be used a lot in the stylesheet you can assign the colour to a variable and instead of rewriting the colour every time you can just substitute in the variable. It helps a lot with reducing redundant coding and can save a lot of time in coding because it’s easier to code functions like defining the hover style for a element instead of creating a separate part you can code it within the original element. The drawbacks are the compile time is increased and debugging becomes harder. it’s also a large change compared to the regular style sheet so if you decided at some point you wanted to remove the pre-processor you’re in a position where the amount of work you’d have to to do remove it would be far more the larger the style sheet is. or the more complicated it is.

17
Q

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

A

You can import a style sheet to import certain fonts, such as google style sheet which has some fonts. You can also use @fontface to declare a custom font. In the past I’ve used an import for google API style to add in fonts in one of my projects.

18
Q

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

A

it starts with the child element and then works it’s way up so for example if you have a style for a bold text which is contained in a list, it’ll first check for bold element, then it’ll look for list and it’ll keep working upwards until it finds the CSS that matches.

19
Q

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

A

Pseudo elements let you control specific parts of elements. For example if you have text that you want to change in some way such as colour when you hover over it, you can use the pseudo element hover to change the style. An example use is if you have a link, you can do li::hover and then change the style to make it appear different for the hover. I used pseudo elements a lot for advanced styling and making the page feel dynamic.

20
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 is how the content on the page is displayed. Everything is displayed within boxes, for example a paragraph tag has a box, a div tag has a box. There’s parameters to these boxes, you have the width and height of the box, padding which is the space within the box that is pushed in for the content, and margin which is a section outside of the box which is used to separate elements. So if you have a box with no margin the next element or box will be touching the current one, if you have no padding the insides of the box will be up to the edges of the container. These values can be changed to design the contents to the way you want it to appear.

21
Q

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

A

this makes it so instead of the margin and padding increasing the size of the container past the defined size, it instead retains the same size. Therefore if you want different padding and margin sizes but want the overall box size to remain the same, this will make it so the padding and margin don’t affect the overall size.

22
Q

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

A

The display property lets you choose how the box of the element will be displayed, for example, you can use flex which will make it flow with the rest of the content such as text which will be moved to the side and will wrap around it. There are other types like block which will make it like a paragraph in where it starts on a new line and any content after will appear on a new line too as it takes up the entire width. in-line is similar to a span in how it will not start a new line or separate content.

23
Q

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

A

The regular inline property does not allow you to resize the width and height of the box, but inline-block does.

24
Q

What’s the difference between the “nth-of-type()” and “nth-child()” selectors?

A

The nth child will use all the elements in the parent element for it’s calculations however the nth of type will only the specific type of element. For example if you have a container which contains a h1 and 5 h2, if you used nth child to change the h2 elements, it’d also use the h1 as part of the number calculations such as with odd and even the first value will be calculated with h1, making the actual sequence for h2 start with even instead. Nth of type will only calculate based on the specific element within the parent such as only h2.

25
What's the difference between a relative, fixed, absolute and statically positioned element?
Static is the default positioning, a relative positioning is where the position of the element is relative to its original position this is technically the same but if you add modifications to the location it'll then use the default or the static position as the base location then apply the modifications to determine the new location. The absolute element is where it's positioned based on the parent element. For example if you have a large container and you use absolute on the child element and then decide to have its position 50 from the right, it'll be 50 from the right of the parent element. This can create overlaps and problems with designing if you have multiple absolute elements.
26
What existing CSS frameworks have you used locally, or in production? How would you change/improve them?
I've used bootstrap in the past for most of my projects because it had a nice simple and consistent style that I could apply around my website which saved time and sorted out the basics. When I used bootstrap I used my own modifications and used bootstrap as the base, this saved me time but also let me create the style the way i want it instead of just using the set designs. There are certain elements which were already perfectly designed for me and all I had to do was some minor modifications such as the colouring, text and few minor details but I feel like when first learning CSS as well as creating a website where the design isn't the main point, bootstrap fills that spot. For my final year project this saved me a lot of time on styling and meant i can just focus on getting the functionality working instead of styling each element as i go along so that i can test and use the website.
27
Have you used CSS Grid?
Yes, in my final year project I had a display of cards using bootstrap which were displayed in a grid across the page. The grid feature lets you work both horizontally and vertically in the same space as opposed to flex box which lets you go 1 or the other. When I was creating my final year project and I had to display products so to speak similar to a online shop, I decided to use CSS grid to have rows and columns with a total of 3 columns and a lot of rows to display all the products.
28
Can you explain the difference between coding a web site to be responsive versus using a mobile-first strategy?
Its just a matter of priority. When you design a website for desktop to be responsive you create it on the largest possible resolution and then you modify it for smaller and smaller resolutions making changes and simplifying parts till it is compatible with phones and smaller devices. The mobile first strategy is where the design is aimed at mobile devices, this means content will be less simple and better designed for mobiles and then you work on desktop resolutions after. The priority usually depends on the main intended target audience. For mobiles the design will be similar to designing an app.
29
Have you ever worked with retina graphics? If so, when and what techniques did you use?
I have not worked with retina graphics unfortunately.
30
Is there any reason you'd want to use translate() instead of absolute positioning, or vice-versa? And why?
The translate uses the element itself as the basis for the location and movement, however using absolute and then positioning will base the location off the parents position with the modifications. While it can be the same, the problem comes if you modify the parent element then the absolute positioning will change, whereas with translate if you modify the location of the element itself the translate will change locations. In general one ties to the parent for its location and the other ties to its own location for the position.
31
How is "clearfix" CSS property useful?
It helps you clear flex boxes so that the parent element wraps around the flex containers that are within. This is the alternative to clearing each flex element manually and it can be useful for styling design so that the boxes for contained content are lined up. you can also use overflow auto to manually clear certain elements.
32
Can you explain the difference between px, em and rem as they relate to font sizing?
PX or pixel is static in that it doesn't change when you zoom in or out. EM and REM scale so that the value is not a flat amount, they're based on the device using them.
33
Can you give an example of a pseudo class? Can you provide an example use case for a pseudo class?
An example of a pseudo class is the hover. One way I used this in my previous projects was for the navigation bar. While it may not be necessary, it makes the page more responsive. the hover pseudo class changes the style of the element when the mouse is hovered over that element. This is common for buttons to give visual response to the user so they can see that they have their mouse over the button. Typically I would have a colour change for the button with a potential text colour change.
34
What is the difference between a block level element and an inline element. Can you provide examples of each type of element?
A block level element is for example the paragraph element and an inline element would be say.. span tag. The paragraph tag which is a block element starts on a new line and creates a new block. The inline element can be used in the middle of a text or line without breaking the line.
35
What is the difference between CSS Grid and Flexbox? When would you use one over the other?
Grid creates an area where you can use the horizontal and vertical axes at one to create a layout similar to a grid. Flexbox on the other hand only lets you work with 1 of these a time. For example you can create sections horizontally or vertically. If i wanted to create something like a section with 9 boxes in a 3 by 3 area i would use CSS grid.