Meine Lieblings-CSS-Fragen mit detaillierten Antworten

Ich habe viele Interviews durchlaufen, und wenn es um CSS-Fragen ging, ging es darum: "Listen Sie alle bekannten Möglichkeiten auf, ein Element zu zentrieren." Nach 5 Antworten bin ich es ehrlich gesagt leid. Deshalb möchte ich meine bevorzugten CSS-Fragen teilen, die ich in einem Interview stelle.


IN 1. Wie kann ich die Deckkraft für ein Schaltflächenelement mit einem deaktivierten Attribut festlegen?


Antworten

, disabled, .


button[disabled] {
  opacity: 0.24;
}

IN 2. Wie kann ich die Deckkraft für das span-Element festlegen, das unmittelbar auf das Eingabeelement folgt?


Antworten

(+).


input + span {
  opacity: 0.24;
}

IN 3. Wie kann ich die Deckkraft für ein Eingabeelement festlegen, dessen Typattribut auf "Radio" gesetzt ist?


Antworten

type="radio" .


input[type="radio"] {
  opacity: 0.24;
}

UM 4. Es gibt ein Code-Snippet. Sagen Sie mir, wie viele Elemente mit magentafarbenem Hintergrund im ersten und zweiten Fall vorhanden sein werden.


<div class="some-element">some text</div>
<div class="some-element">some text</div>
<article class="some-element">some text</article>

Fall 1


.some-element:first-child {
  background-color: purple;
}

Fall 2


.some-element:first-of-type {
  background-color: purple;
}

Antworten

, — 2.


UM 5. Was ist die Pseudoklasse: root?


Antworten

:root — , . HTML html. SVG svg.


UM 6. Wie funktioniert die: Platzhalter-angezeigte Pseudoklasse?


Antworten

:placeholder-shown , input textarea placeholder. , placeholder , :placeholder-shown .


input:placeholder-shown {
  background-color: lightgray;
}

UM 7. Wie kann ich CSS für ein Element festlegen, bei dem ein Element im Fokus steht?


Antworten

:focus-within.


<div class="some-parent">
  <button type="button">Some button</button>
</div>

.some-parent:focus-within {
  outline: 2px solid purple;
  outline-offset: 5px;
}

UM 8. Stellen Sie sich vor, es gibt eine Tabelle mit Daten. Wie kann die Deckkraft für alle Zeilen hinzugefügt werden, außer für die, auf die der Benutzer hingewiesen hat?


Antworten

. tbody:hover , opacity . opacity , :not(:hover).


tbody:hover tr:not(:hover) {
  opacity: 0.24;
}

UM 9. Wie kann ich den folgenden Code neu schreiben, damit sich der Wert der Hintergrundfarben-Eigenschaft automatisch ändert, wenn sich der Wert der Farbeigenschaft ändert?


.link {
  color: #222;
}

.link::before {
  background-color: #222;
}

Antworten

currentColor, color . .link.


.link {
  color: #222;
}

.link::before {
  background-color: currentColor;
}

UM 10. Die Maßeinheit rem wird in Abhängigkeit vom Wert der Schriftgrößeneigenschaft des HTML-Elements berechnet. Wahrheit oder Lüge?


Antworten

.


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>

div , .


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 ?


height .


16. . ?


.


17. .child — 196x196px. ?


<body>
  <span class="child">element</span>
</body>

.child {
  width: 196px;
  height: 196px;
}

, width height , .


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;
}

- , . , .parent .


22. span ?


span {
  width: 300px;
  height: 300px;
  position: absolute;
}

300x300px, span .


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;
}

. - . — 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;
}

30px, - .


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;
}

150px.


B30 Wie groß ist das Span-Element im folgenden Beispiel?


<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;
}

Antworten

225px. flex-basis width, min-width max-width. 250px (flex-basis) , 225px.


All Articles