HTML Css Questions
HTML Css Questions
---
---
---
---
* Descendant Combinator
* This is the most common usage, e.g. #lovelyweather h1.
* Child Combinator
* Select an element if it is a direct child of another element
(and not a grandchild of that element).
* Adjacent Sibling Combinator
* The element that is immediately adjacent to another element.
* General Sibling Combinator
* The element that is adjacent, but not immediately to another
element.
---
---
---
---
```css
/* block component */
.block {
}
/* element */
.block__element {
}
/* modifier */
.block__element--modifier {
}
```
```css
<nav class="navbar">
<a href="/" class="navbar__link navbar__link--active"></a>
<a href="/" class="navbar__link"></a>
<a href="/" class="navbar__link"></a>
</nav>
```
```css
<a href="/" class="navbar__link is-active"></a>
```
```css
.navbar__link.is-active {
}
```
###### References
* https://css-tricks.com/bem-101/
---
---
---
---
#### Explain CSS sprites, and how you would implement them
on a page or site. How do you go about creating them? What are
possible alternatives to sprites?
* Use a sprite generator that packs multiple images into one and
generate the appropriate CSS for it.
* Each image would have a corresponding CSS class with
`background-image`, `background-position` and `background-
size` properties defined.
* To use that image, add the corresponding class to your element.
**Advantages:**
* Reduce the number of ```HTTP``` requests for multiple images
(only one single request is required per spritesheet). But with
```HTTP2```, loading multiple images is no longer much of an
issue.
* Advance downloading of assets that won't be downloaded until
needed, such as images that only appear upon `:hover` pseudo-
states. Blinking wouldn't be seen.
**Alternatives:**
* Data URIs - allow you to embed the image data directly into a
stylesheet. This avoids additional HTTP requests for images,
making it essentially the same thing as a sprite, without the fancy
positioning.
* Icon Fonts
* SVGs
---
CSS sprites combine multiple images into one image, limiting the
number of HTTP requests a browser has to make, thus improving
load times. Even under the new HTTP/2 protocol, this remains
true.
---
#### What is the CSS Box model and what are its elements?
* The CSS box model is used to define the design and layout of
elements of CSS.
* The elements are:
* Margin
* Border
* Padding
* Content
---
* if you set, 'float: left;' for an image, it will move to the left until
the margin, padding or border of another block-level element is
reached. The normal flow will wrap around on the right side.
---
---
---
---
---
---
---
#### What are CSS frameworks? What CSS frameworks have
you used
It is a pre-planned libraries, which allows easier and more
standards-compliant webpage styling, using CSS language.
---
---
#### What are the pros and cons of using absolute positioning?
---
* ```block```:
* respect all of those
* force a line break after the block element
* breaks the flow
* ```inline```:
* respect left & right margins and padding, but not top &
bottom
* cannot have a width and height set
* margin and padding will push other elements horizontally
not vertically
* allow other elements to sit to their left and right.
* elements do not break the flow
* ```inline-block```:
* allow other elements to sit to their left and right
* respect top & bottom margins and padding
* respect height and width
---
* No
---
* https://css-tricks.com/multiple-class-id-selectors
---
---
* No
---
#### Does padding-top or padding-bottom has effect on inline
element?
* No
---
* ```%``` sets font-size relative to the font size of the body. Hence,
you have to set font-size of the body to a reasonable size. this is
easy to use and does cascade. for example, if parent font-size is
20px and child font-size is 50%. child would be 10px.
* Yes
---
#### If you have a <p> element with font-size: 10rem, will the
text be responsive when the user resizes / drags the browser
window?
* No
---
```css
p::first-line {
color: #ff0000;
font-variant: small-caps;
}
```
---
* True
---
---
#### The pseudo class :checked will select inputs with type radio
or checkbox, but not <option> elements.
* False
---
```css
/* top right bottom left */
padding: 25px 50px 75px 100px;
---
---
* SASS (SCSS)
* LESS
* Stylus
* PostCSS
---
*Advantages:*
*Disadvantages:*
---
---
---
---
---
#### Explain your understanding of the box model and how you
would tell the browser in CSS to render your layout in different
box models.
* The content of the space taken by an element. Each element has
an inner and outer height/width calculated based on the content,
padding, border and margin.
```content-box``` default. Excludes padding, border and margin
from the inner dimensions.
```border-box``` includes the padding and border, but not the
margin in the inner dimension.
The CSS box model describes the rectangular boxes that are
generated for elements in the document tree and laid out
according to the visual formatting model. Each box has a content
area (e.g. text, an image, etc.) and optional surrounding `padding`,
`border`, and `margin` areas.