我经历了很多采访,当涉及CSS问题时,他们归结为:“列出所有已知的使元素居中的方式。” 坦率地说,经过5封回复,我已经厌倦了。因此,我想分享我在采访中提出的最喜欢的CSS问题。
输入1。如何为具有禁用属性的按钮元素设置不透明度?
回答, disabled, .
button[disabled] {
opacity: 0.24;
}
输入2。如何设置紧接在输入元素之后的span元素的不透明度?
回答(+).
input + span {
opacity: 0.24;
}
IN 3。如何为type属性设置为“ radio”的输入元素设置不透明度?
回答type="radio" .
input[type="radio"] {
opacity: 0.24;
}
在4。有一个代码段。告诉我在第一种情况和第二种情况下将有多少个具有洋红色背景的元素。
<div class="some-element">some text</div>
<div class="some-element">some text</div>
<article class="some-element">some text</article>
情况1
.some-element:first-child {
background-color: purple;
}
情况2
.some-element:first-of-type {
background-color: purple;
}
在5。什么是伪类:root?
回答:root — , . HTML html. SVG svg.
在6点钟。占位符显示的伪类如何工作?
回答:placeholder-shown , input textarea placeholder. , placeholder , :placeholder-shown .
input:placeholder-shown {
background-color: lightgray;
}
7岁时。如何为具有焦点的元素设置CSS?
回答:focus-within.
<div class="some-parent">
<button type="button">Some button</button>
</div>
.some-parent:focus-within {
outline: 2px solid purple;
outline-offset: 5px;
}
在8点。想象有一个包含数据的表。除了用户指向的那一行以外,为所有行添加不透明度的方法是什么?
回答. tbody:hover , opacity . opacity , :not(:hover).
tbody:hover tr:not(:hover) {
opacity: 0.24;
}
在9。我如何重写以下代码,以便当color属性的值更改时background-color属性的值自动更改?
.link {
color: #222;
}
.link::before {
background-color: #222;
}
回答currentColor, color . .link.
.link {
color: #222;
}
.link::before {
background-color: currentColor;
}
在10。根据html元素的font-size属性的值计算度量单位rem。真理还是谎言?
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 在以下示例中,span元素的大小是多少?
<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;
}
回答225px. flex-basis width, min-width max-width. 250px (flex-basis) , 225px.