通过构建一组彩色笔来学习 CSS 颜色 - 步骤 78

告诉我们发生了什么:
在此详细描述你的问题。
如何同时定位cap和sleeve
你目前的代码

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Colored Markers</title>
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
    <h1>CSS Color Markers</h1>
    <div class="container">
      <div class="marker red">
        <div class="cap"></div>
        <div class="sleeve"></div>
      </div>
      <div class="marker green">
      </div>
      <div class="marker blue">
      </div>
    </div>
  </body>
</html>
/* file: styles.css */
h1 {
  text-align: center;
}

.container {
  background-color: rgb(255, 255, 255);
  padding: 10px 0;
}

.marker {
  width: 200px;
  height: 25px;
  margin: 10px auto;
}

.cap {
  width: 60px;
  height: 25px;
}

.sleeve {
  width: 110px;
  height: 25px;
  background-color: rgba(255, 255, 255, 0.5);
}


/* User Editable Region */

.sleeve{
  display:inline-block;
}
.cap{
  display:inline-block;
}

/* User Editable Region */


.red {
  background: linear-gradient(rgb(122, 74, 14), rgb(245, 62, 113), rgb(162, 27, 27));
}

.green {
  background: linear-gradient(#55680D, #71F53E, #116C31);
}

.blue {
  background: linear-gradient(hsl(186, 76%, 16%), hsl(223, 90%, 60%), hsl(240, 56%, 42%));
}

你的浏览器信息:

用户代理是: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36

挑战: 通过构建一组彩色笔来学习 CSS 颜色 - 步骤 78

挑战的链接:

You should use a selector list containing both classes.

sorry,i no understand can you explain,because i follow this method is no

.is (cap,sleeve){
display:inline-block;
}

在学习编程时,查文档和读文档是很重要的。freeCodeCamp 提倡 read-search-ask 学习方法,就是先认真读题,然后自己搜索如何解决,如果仍然无法解决,再提问。

你可以看 @lasjorg 分享的 MDN 文档的中文版(在网页上可以很方便地选择语言):

其中有举例如何同时为 span 和 div 两个 class 设置 border。

有两种方法:

span,
div {
  border: red 2px solid;
}
:is(span, div) {
  border: red 2px solid;
}

看起来你用的是第二种,但是 is 前面应该是冒号,而不是一个句点。

至于 :is() 是什么意思,你仍然可以在 MDN 搜索到:

我们不会直接告诉你答案,因为这对你自学进步是没有帮助的。

I guess it is a bit confusing how the MDN docs talk about the :is() and :has() selectors.

I’m specifically talking about the section on Single line grouping/Multi line grouping and the CSS example they show.


Technically, the challenge should allow you to use :is() but it doesn’t and it isn’t really the expected selector so I guess that is fine (even if the CSS it applies is correct).

:is (cap, sleeve){
display: inline-block;
}

You are not to use the :is() selector. You should use a selector list.

p,
h1 {
  display: inline-block;
}

Do the same but for with the selectors .sleeve and .cap

.sleeve,
.cap {
  /* the style asked for */
}