I went through a lot of interviews, and when it came to CSS questions, they came down to: "List all the known ways to center an element." After 5 replies, frankly, I'm tired of it. So I want to share my favorite CSS questions that I ask in an interview.
IN 1. How can I set the opacity for a button element that has a disabled attribute?
Answer, disabled, .
button[disabled] {
opacity: 0.24;
}
IN 2. How can I set the opacity for the span element that immediately follows the input element?
Answer(+).
input + span {
opacity: 0.24;
}
IN 3. How can I set the opacity for an input element that has the type attribute set to "radio"?
Answertype="radio" .
input[type="radio"] {
opacity: 0.24;
}
AT 4. There is a code snippet. Tell me how many elements with a magenta background will be in the first and second case.
<div class="some-element">some text</div>
<div class="some-element">some text</div>
<article class="some-element">some text</article>
case 1
.some-element:first-child {
background-color: purple;
}
case 2
.some-element:first-of-type {
background-color: purple;
}
AT 5. What is the pseudo-class: root?
Answer:root — , . HTML html. SVG svg.
AT 6. How does the: placeholder-shown pseudo-class work?
Answer:placeholder-shown , input textarea placeholder. , placeholder , :placeholder-shown .
input:placeholder-shown {
background-color: lightgray;
}
AT 7. How can I set CSS for an element that has an element in focus?
Answer:focus-within.
<div class="some-parent">
<button type="button">Some button</button>
</div>
.some-parent:focus-within {
outline: 2px solid purple;
outline-offset: 5px;
}
AT 8. Imagine that there is a table with data. What is the way to add opacity for all lines except the one that the user has pointed at?
Answer. tbody:hover , opacity . opacity , :not(:hover).
tbody:hover tr:not(:hover) {
opacity: 0.24;
}
AT 9. How can I rewrite the following code so that the value of the background-color property changes automatically when the value of the color property changes?
.link {
color: #222;
}
.link::before {
background-color: #222;
}
AnswercurrentColor, color . .link.
.link {
color: #222;
}
.link::before {
background-color: currentColor;
}
AT 10. The unit of measure rem is calculated depending on the value of the font-size property of the html element. Truth or lie?
11. button 16px font-size. 8px padding em?
8px 16px.
button {
font-size: 16px;
padding: .5em;
}
12. 10vw padding-left. px, — 480x320px?
vw — . 10vw 10% , . 480px. 10vw 48px.
13. div ?
<body>
<div>element 1</div>
<div>element 2</div>
</body>
14. width .child 1000px. ? ?
<body>
<div class="parent">
<div class="child">element 2</div>
</div>
</body>
.parent {
width: 1000px;
}
. width . width .child width .
15. height ?
16. . ?
17. .child — 196x196px. ?
<body>
<span class="child">element</span>
</body>
.child {
width: 196px;
height: 196px;
}
18. .child ?
<body>
<div class="parent">
<div class="child">element 2</div>
</div>
</body>
.child {
margin-top: 10px;
}
, .child .parent, margin .
19. display ?
span {
display: inline-block;
position: absolute;
}
block. position: absolute . inline-block block.
20. width .child 1000px. ? ?
<body>
<div class="parent">
<div class="child">element 2</div>
</div>
</body>
.parent {
width: 1000px;
}
.child {
position: absolute;
}
. position: absolute width .
21. .parent ?
<body>
<div class="parent">
<div class="child">element 2</div>
</div>
</body>
.child {
position: absolute;
}
22. span ?
span {
width: 300px;
height: 300px;
position: absolute;
}
23. .child 20px .parent. ?
<body>
<div class="parent">
<div class="child">element 2</div>
</div>
</body>
.parent {
box-sizing: border-box;
width: 1000px;
padding: 20px;
}
.child {
position: absolute;
}
. position: absolute , , top, right, bottom, left. .child 20px , position: absolute .
24. display ?
span {
display: inline-block;
position: relative;
}
inline-block, .. position: relative, display.
25. span ?
span {
width: 300px;
height: 300px;
display: flex;
}
display: flex, . width height span. — 300x300px.
26. .child display inline-block. ?
<div class="parent">
<span class="child">element2</span>
</div>
.parent {
display: flex;
}
.child {
display: inline-block;
}
27. width .child . ?
<div class="parent">
<div class="child">element2</div>
</div>
.parent {
display: flex;
}
28. ?
<body>
<div class="parent">
<div class="first-child">element 1</div>
<div class="second-child">element 2</div>
</div>
</body>
.parent {
display: flex;
flex-direction: column;
}
.first-child {
margin-bottom: 20px;
}
.second-child {
margin-top: 10px;
}
29. .child ?
<div class="parent">
<span class="child">element2</span>
</div>
.parent {
display: flex;
width: 250px;
height: 250px;
}
.child {
width: 100px;
height: 100px;
margin-top: auto;
margin-left: auto;
}
B30 What are the sizes of the span element in the following example?
<div class="parent">
<span class="child">element2</span>
</div>
.parent {
display: flex;
}
.child {
flex-basis: 250px;
width: 100px;
height: 200px;
min-width: 150px;
max-width: 225px;
}
Answer225px. flex-basis width, min-width max-width. 250px (flex-basis) , 225px.