我刚开始接触编程(几周前刚刚学习了HTML和CSS)。为新闻页面,我尝试实现“阅读更多”链接,类似于这个问题:on click hide this (button link) pure css
然而,我似乎无法在单击后使链接消失。到目前为止,我的代码如下(打开和关闭都可以正常工作):
.readmore {
display: none;
}
article[id*="n"]:target .readmore {
display: block;
}
article:target .used {
display: none;
}
<article>Text visible after you open the site.
<a href="#n2" class="used">Link that opens more text and should diappear after clicking</a>
<article id="n2">
<div class="readmore">more text
<a href="#back">Closing button</a>
</div>
</article>
</article>
我感觉自己犯了一个非常严重的错误,但我真的无法找出问题所在。
:target
matches an element with the id of the URL's fragment, but that element (#n2
) has no children.used
- Ricardo Ribeiro