【问题标题】:2 classes of css with same name and call them individually [closed]2类具有相同名称的css并单独调用它们[关闭]
【发布时间】:2019-07-29 17:14:36
【问题描述】:

我有两个同名的班级

.class{ ...}
.class{ ...}

我想同时调用两个类。

<p class="class">first class</p>  
<p class="class">second class</p>  

一些帮助。

【问题讨论】:

标签: html css


【解决方案1】:

检查这个例子:

  • .class全选
  • .class:first-child只选择第一个
  • .class:last-child 只选择最后一个
  • .class:last-child只选择指定位置

已编辑:我添加了内联样式来修改单个元素而不修改 css 文件(如您在评论中的要求)

.class{
  color:red;
}

.class:first-child {
  background: yellow;
}

.class:last-child  {
  background: green;
}

.class:nth-child(2n) {
  background: purple;
}
<div class="wrapper">
  <p class="class">first class</p>  
  <p class="class">second class</p>
  <p class="class">last class</p>  
</div>


<div class="wrapper-inline">
  <p style="color:red">first class</p>  
  <p style="color:green">second class</p>
  <p style="color:blue">last class</p>  
</div>

【讨论】:

  • 不错@red,但我想在没有选择器的情况下执行此操作,我无法更改 css 文件,有什么办法吗?
  • 在我编辑的答案中查看样式的内联版本
  • 不,我有我只想使用它的类,内联样式不是一个选项。好吧,我会接受它,因为没有办法随心所欲地使用课程,是吗?
  • 不抱歉,唯一的办法是使用不同的类名
猜你喜欢
  • 1970-01-01
  • 2017-01-22
  • 2019-09-30
  • 2014-03-29
  • 1970-01-01
  • 1970-01-01
  • 2016-11-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多