CSS Question Flashcards

1
Q

If we link two CSS files with our HTML, which one will have priority?

A

The priority of linked CSS files is determined by the order in which they are included in the HTML document. If two CSS files define conflicting styles for the same element, the styles from the CSS file linked last will take precedence and override the styles from the previous CSS file.

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

When we link our external CSS to our HTML, do we link it only once?

A

You only need to link your external CSS file once in your HTML document. Typically, the CSS file is linked in the <head> section of the HTML using the <link> tag. Once linked, the styles defined in the CSS file will be applied to the entire HTML document.

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

Why does not my CSS link to my HTML without adding two dots when using relative reference?

A

When using relative references to link CSS files, you may need to add two dots (../) to indicate moving up one level in the directory structure. This is necessary when the CSS file is located in a different folder than the HTML file. The two dots represent the parent directory, allowing the browser to correctly locate the CSS file.

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

Why is using external CSS recommended rather than inline and internal CSS?

A

Using external CSS is recommended for several reasons:
- Separation of concerns: External CSS allows you to separate the styling (CSS) from the structure (HTML) and behavior (JavaScript). This makes your code more modular, maintainable, and easier to update.
- Reusability: With external CSS, you can apply the same styles to multiple HTML pages, promoting consistency across your website.
- Caching: When using external CSS, the browser can cache the CSS file, resulting in faster page loading times for subsequent visits to the site.
- Collaboration: External CSS facilitates collaboration among developers, as different team members can work on HTML and CSS independently.

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

Is it the best practice to have our external CSS file in the same project folder as our html file?

A

While it is not mandatory, it is considered a best practice to keep your external CSS file in the same project folder as your HTML file. Organizing your files in a logical structure helps improve maintainability and makes it easier to locate and manage the related files.

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

Where in the HTML should we link our CSS file?

A

The <link> tag is placed within the <head> section of the HTML document. It should include the rel attribute set to “stylesheet” and the href attribute specifying the path to the CSS file. An example of linking a CSS file named “styles.css” would be: <link rel="stylesheet" href="styles.css">.

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

Can we use one CSS file to different HTML pages?

A

Yes, you can use one CSS file for multiple HTML pages by linking the same CSS file in all of the HTML documents. As long as the CSS file is properly linked, it will be applied to all the HTML pages, ensuring consistent styling across the website.

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

Does percentage unit represent percentage in relation to the browser’s size?

A

The percentage unit in CSS represents a proportion relative to the size of the element’s parent container, not the browser size. For example, if an element’s width is set to 50%, it means it will occupy 50% of the width of its parent container.

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

Can we just use percentage or pixel to style?

A

Both percentage and pixel units can be used for styling, but they serve different purposes. Percentages are useful when you want elements to scale dynamically based on their parent container’s size. Pixels, on the other hand, provide fixed measurements and are useful for specifying precise dimensions or positions that don’t need to change with the parent container’s size.

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

How do we know the exact measurement of a design, for instance height of an image?

A

To determine the exact measurements of a design element, such as the height of an image, you can use web development tools provided by browsers. These tools, accessible through browser developer tools (usually by right-clicking on an element and selecting “Inspect” or similar options), allow you to examine the dimensions, margins, and other properties of an element on a web page.

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

If we don’t have a direct parent for our HTML tag, relative to what will em be calculated?

A

The “em” unit is calculated relative to the font size of the nearest parent element that has a font size explicitly set. If there is no direct parent with a font size set, the calculation falls back to the font size of the root element, which is typically the <html> element.

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

How do we decide whether to put an element in a container?

A

The decision to put an element in a container depends on the specific layout and design requirements of your web page. Containers are commonly used to group related content or create specific layout structures. You can use containers like <div> elements to apply shared styles, control positioning, or create visual sections within your HTML document.

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

Is putting a space and hyphen between two class names the same?

A

In CSS, a space between class names indicates that an element has multiple classes applied to it. It means the element will inherit styles from all the specified classes. On the other hand, a hyphen between class names is not valid syntax and will be treated as part of the class name itself.

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

Is it preferable to give our id or class a meaningful name?

A

It is highly recommended to give meaningful names to classes and IDs to improve code readability, maintainability, and collaboration. Using descriptive names that reflect the purpose orfunctionality of the element or group of elements helps make the code more understandable and easier to work with.

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

Why do we need to use id and class for one HTML element?

A

IDs and classes are used to apply specific styles or target specific elements in CSS or JavaScript. IDs are typically used to uniquely identify a single element on a page, while classes can be applied to multiple elements to group them together or share common styles.

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

Can we have more than one Id in one HTML?

A

According to HTML standards, each ID must be unique within an HTML document. Having multiple elements with the same ID is considered invalid and can lead to unexpected behavior. IDs should be unique identifiers for individual elements.

17
Q

Can we use one name for Id and Class?

A

Yes, you can use the same name for an ID and a class. There is no inherent conflict between the two. However, it’s important to remember that IDs must be unique within an HTML document, while classes can be applied to multiple elements.

18
Q

Are class and Id names case sensitive?

A

Class and ID names are case-sensitive in HTML and CSS. For example, a class or ID named “myClass” is different from “myclass” or “MyClass”. It’s important to be consistent with the case when referencing classes and IDs in your HTML and CSS code.

19
Q

If we give the same class name to several elements, how do we style one of the elements differently?

A

If you have multiple elements with the same class name and you want to style only one of them differently, you can use additional selectors to target that specific element. For example, you can use a more specific CSS selector, like an ID or a parent element, to override the styles for that particular element.

20
Q

How can we select only one div from the many divs in our HTML and then style?

A

To select and style a specific <div> element, you can use a unique ID assigned to that <div> or a more specific CSS selector targeting its parent elements. For example, if the <div> has an ID of “myDiv”, you can target it using #myDiv in CSS. Alternatively, you can use parent-child relationships or other CSS selectors to narrow down the selection.

21
Q

What is the difference between using star selector and body selector?

A

The star selector (*) targets all elements in an HTML document, applying styles to every element on the page. This can be useful for applying global styles or resetting default styles. On the other hand, the body selector (body) specifically targets the <body> element, allowing you to apply styles to the entire body of the document.

22
Q

What do we mean by multiple selectors?

A

Multiple selectors refer to the technique of combining multiple CSS selectors together, separated by commas, to target specific elements. This allows you to apply the same styles to multiple elements with different tag names, classes, or IDs without having to duplicate the styles. For example, h1, h2, h3 selects all <h1>, <h2>, and <h3> elements to apply the same styles to all of them.