css - 在div中定位两个元素而不重复父类

时间:2016-09-07 05:48:46

标签: css css3

例如,我就是这个 -

<div class="epindiv"><p>Enter No. of Epins:</p> <input size="2" type="text" /> <div class="clear-both"></div></div>

我想定位<p>代码和<input/>代码。但我不想这样写 -

.epindiv p, .epindiv input

有没有更有效的方式来编写它而不重复父类?

1 个答案:

答案 0 :(得分:3)

在这种特殊情况下,您可以使用.epindiv *:not(:last-child)

.epindiv *:not(:last-child) {
  background: orange;
}
<div class="epindiv">
  <p>Enter No. of Epins:</p>
  <input size="2" type="text" />
  <div class="clear-both"></div>
</div>