我有分页
如何在点击其他链接时更改pagination__link
的文字“左”的背景?只需要使用CSS。
答案 0 :(得分:1)
你可以做到这一点,但坦率地说它很混乱,使用CSS灵活盒以及相对较新的:focus-within
伪类。这确实需要颠倒<li>
中<ul>
元素的顺序:
.pagination {
/* sets the display to use the flex layout: */
display: flex;
/* ensures the contents of the <ul> are shown in
columns and in reverse-order: */
flex-direction: column-reverse;
}
/* selects first the <li> that has a focused element
within it, then finds all subsequent <li> elements,
using the general-sibling combinator ('~') that
also matches the :last-child pseudo-class (there can,
obviously, be only one) then finds the <a> element(s)
which is a child of that <li> element: */
li:focus-within ~ li:last-child > a {
background - color: red;
}
&#13;
<ul class="pagination">
<li class="pagination__item pagination__item--active">
<a class="pagination__link" href="#">
Page 2
</a>
</li>
<li class="pagination__item">
<a class="pagination__link" href="#">
Page 1
</a>
</li>
<li class="pagination__item">
<a class="pagination__link" href="#">
left
</a>
</li>
</ul>
&#13;
参考文献:
:focus-within
。flex-direction
。~
) 答案 1 :(得分:0)
ServerChannel
&#13;
input[name="radio"]{
display: none;
}
label{
text-decoration: underline;
color: blue;
}
input[name="radio"]:checked + label{
background-color: yellow;
}
&#13;
也许它不是你想要的答案。
但我认为这可以很好地暗示你的问题。
您可以使用复选框技巧或无线电技巧。