Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 使用css隐藏展开的文本节点 2017年6月3日_Html_Css - Fatal编程技术网

Html 使用css隐藏展开的文本节点 2017年6月3日

Html 使用css隐藏展开的文本节点 2017年6月3日,html,css,Html,Css,上面的html将输出 2017年6月3日由Albert发表评论 但我想躲在阿尔伯特身边。问题是我不能通过隐藏,因为它没有包装在任何html标记中。可见性可以在子元素上覆盖。因此,我们可以仅自定义根文本节点: <p class="entry-meta"><time class="entry-time" itemprop="datePublished" datetime="2017-06-03T02:58:22+00:00">June 3, 2017</time>

上面的html将输出

2017年6月3日由Albert发表评论


但我想躲在阿尔伯特身边。问题是我不能通过隐藏
,因为它没有包装在任何html标记中。

可见性
可以在子元素上覆盖。因此,我们可以仅自定义根文本节点:

<p class="entry-meta"><time class="entry-time" itemprop="datePublished" datetime="2017-06-03T02:58:22+00:00">June 3, 2017</time> by <span class="entry-author" itemprop="author" itemscope="" itemtype="http://schema.org/Person"><a href="http://example.com/author/Albert/?customize_changeset_uuid=f30e84b8-4ed2-415a-9482-75fc161d62df&amp;customize_messenger_channel=preview-0" class="entry-author-link" itemprop="url" rel="author" target="_self"><span class="entry-author-name" itemprop="name">Albert</span></a></span> <span class="entry-comments-link"><a href="http://example.com/category/4-way-to-change-mac-engine/?customize_changeset_uuid=f30e84b8-4ed2-415a-9482-75fc161d62df&amp;customize_messenger_channel=preview-0#respond" target="_self">Leave a Comment</a></span> </p>
问题是可见性仍然占用空间:

p.entry-meta{visibility:hidden;}
p、 条目元时间,p.entry-meta span.entry-comments-link{可见性:可见;}

2017年6月3日


使用以下CSS删除文本:

.entry作者姓名{display:none;}
p{字体大小:0;}
p>*{
字体大小:12px;
}

2017年6月3日


您可以使用JavaScript执行此操作-选择段落DOM元素并将其分配给变量,然后一次删除一个子节点:

    var el = document.querySelector(".entry-time").innerText;

    document.querySelector(".entry-meta").innerText=el;

添加css。条目作者姓名{display:none;}不起作用,它仍然保留“by”:
2017年6月3日,通过留下评论
不起作用,它仍然保留“by”:2017年6月3日,通过留下评论Hi Alan,运行代码段,我相信“by”不再可见。只是好奇为什么
by
不见了?我知道这是你的问题:隐藏“作者”,但你在隐藏“by”时遇到了问题,因为它没有包装在任何标记中。
    var el = document.querySelector(".entry-time").innerText;

    document.querySelector(".entry-meta").innerText=el;
var entryMetas = document.getElementsByClassName("entry-meta");

for (var i = 0; i < entryMetas.length; i++){
    entryMetas[i].removeChild(entryMetas[i].childNodes[2]);
    entryMetas[i].removeChild(entryMetas[i].childNodes[1]);
}
p.entry-meta span.entry-author-name{ display: inline-block; width: 0px; }