在元素中隐藏文本节点,但不隐藏子节点 [英] Hide text node in element, but not children

查看:140
本文介绍了在元素中隐藏文本节点,但不隐藏子节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点麻烦的CSS,似乎找不到一个解决方案。我有这个HTML

I'm having a little trouble with CSS and can't seem to find a solution. I have this HTML

<div id="closelink">
  <a href="">Close</a>
  Click to close
</div>

现在我想隐藏文本«点击关闭»,而不隐藏div,

Now I want to hide the text «Click to close» only, without hiding neither the div, nor the link within it.

可以这样做吗?

推荐答案

visibility 属性可以覆盖children元素,因此您可以这样做:

The visibility attribute can be overriden on children elements, so you are able to do this:

<div id="closelink">
  <a href="">Close</a>
  Click to close
</div>

CSS:

#closelink {
    visibility:collapse;
}

#closelink a{
    visibility:visible;
}

结果是: http://jsfiddle.net/pavloschris/Vva84/

这篇关于在元素中隐藏文本节点,但不隐藏子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆