我有这个表单,我试图定位某个没有自己的类的元素。不幸的是,我无法更改 html。
我正在尝试定位最后一个 .formfield
元素,然后是第二个 p
之后标记。
我试过 :last-child
, :last-of-type
和:nth-last-child()
但我似乎无法得到最后一个。
使用下面的 html,我如何定位 <p>Target me</p>
?
.form form[name="pageform"] .formfield:last-child+p+p {
color: red;
}
<div class="form">
<form enctype="" name="pageform" onsubmit="formhandler(); return true;" action="#" method="post">
<input type="hidden" name="form_submitted" value="1">
<div class="formfield">...
</div>
<div class="formfield">...
</div>
<div class="formfield">...
</div>
<p><input type="checkbox" name="gdpr-accept"></p>
<p>Target me</p>
<div id="submit_div">
<input type="submit" id="submit_button" value="Send">
</div>
</form>
</div>
最佳答案
您不能定位上一个类。您可以使用基于 HTML 元素顺序的东西,例如:
.formfield + p + p { }
或者这个:
div:nth-last-of-type(2) + p + p { }
关于html - 针对表单中的最后一个表单字段,然后是一些,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55630269/