【问题标题】:I have two same cIass name and one style is possible to apply style for first div class?我有两个相同的 cIass 名称,一个样式可以为第一个 div 类应用样式?
【发布时间】:2021-12-26 10:33:50
【问题描述】:

我有两个像这样的 div:

<div class="circle">
<div class="circle">

我有一种风格:

.circle{
    width="100";
    height="200";
}

在这种情况下,我的 css 仅适用于第一个 div,这可能吗?

【问题讨论】:

标签: javascript php html css web


【解决方案1】:

使用.circle:first-child 即可解决问题

.circle:first-child {
  height: 100px;
  width: 100px;
  background: red;
}
<div class="circle">First child</div>
<div class="circle">Second child</div>

【讨论】:

    猜你喜欢
    • 2023-02-07
    • 2012-06-17
    • 1970-01-01
    • 1970-01-01
    • 2011-03-03
    • 1970-01-01
    • 1970-01-01
    • 2020-08-14
    • 2014-04-23
    相关资源
    最近更新 更多